Skip to content

Commit

Permalink
Add axios dependency (#52)
Browse files Browse the repository at this point in the history
* Add axios dependency
* Refactor APIClient to use abstract class and interface
  • Loading branch information
mdwiltfong authored Jan 30, 2024
1 parent 3a2b1d0 commit af9d9f0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
35 changes: 35 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@hookform/resolvers": "^3.3.4",
"@reduxjs/toolkit": "^2.0.1",
"@testing-library/react": "^14.1.2",
"axios": "^1.6.6",
"bootstrap": "^5.3.2",
"jsdom": "^23.0.1",
"localforage": "^1.10.0",
Expand Down
23 changes: 23 additions & 0 deletions client/src/util/APIClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import axios, { AxiosInstance, AxiosResponse } from "axios";
import config from "../../../server/utils/Config";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
abstract class APIHelper {
protected instance: AxiosInstance;
constructor() {
this.instance = axios.create({
baseURL:
config.NODE_ENV === "production"
? "https://codecademy-secret-santa-2.fly.dev"
: `http://localhost:${config.PORT}`,
timeout: 5000,
});
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface APIClientI {
get: <T>(url: string) => Promise<AxiosResponse<T>>;
post: <T>(url: string, body: object) => Promise<AxiosResponse<T>>;
put: <T>(url: string, body: object) => Promise<AxiosResponse<T>>;
delete: <T>(url: string) => Promise<AxiosResponse<T>>;
}

0 comments on commit af9d9f0

Please sign in to comment.