-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from huwshimi/custom-axios-instance
WD-14004 - feat: add custom axios instance
- Loading branch information
Showing
9 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import axios from "axios"; | ||
import { apiBasePath } from "util/basePaths"; | ||
|
||
export const axiosInstance = axios.create({ baseURL: apiBasePath }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
import { Client } from "types/client"; | ||
import { PaginatedResponse, ApiResponse } from "types/api"; | ||
import { handleRequest, PAGE_SIZE } from "util/api"; | ||
import axios from "axios"; | ||
import { axiosInstance } from "./axios"; | ||
|
||
export const fetchClients = ( | ||
pageToken: string, | ||
): Promise<PaginatedResponse<Client[]>> => | ||
handleRequest(() => | ||
axios.get<PaginatedResponse<Client[]>>( | ||
axiosInstance.get<PaginatedResponse<Client[]>>( | ||
`/clients?page_token=${pageToken}&size=${PAGE_SIZE}`, | ||
), | ||
); | ||
|
||
export const fetchClient = (clientId: string): Promise<ApiResponse<Client>> => | ||
handleRequest(() => axios.get<ApiResponse<Client>>(`/clients/${clientId}`)); | ||
handleRequest(() => | ||
axiosInstance.get<ApiResponse<Client>>(`/clients/${clientId}`), | ||
); | ||
|
||
export const createClient = (values: string): Promise<ApiResponse<Client>> => | ||
handleRequest(() => axios.post<ApiResponse<Client>>("/clients", values)); | ||
handleRequest(() => | ||
axiosInstance.post<ApiResponse<Client>>("/clients", values), | ||
); | ||
|
||
export const updateClient = ( | ||
clientId: string, | ||
values: string, | ||
): Promise<ApiResponse<Client>> => | ||
handleRequest(() => | ||
axios.post<ApiResponse<Client>>(`/clients/${clientId}`, values), | ||
axiosInstance.post<ApiResponse<Client>>(`/clients/${clientId}`, values), | ||
); | ||
|
||
export const deleteClient = (client: string) => | ||
handleRequest(() => | ||
axios.get<ApiResponse<string>>(`/clients/${client}`, { | ||
axiosInstance.get<ApiResponse<string>>(`/clients/${client}`, { | ||
method: "DELETE", | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
import { handleRequest } from "util/api"; | ||
import { IdentityProvider } from "types/provider"; | ||
import axios from "axios"; | ||
import { PaginatedResponse, ApiResponse } from "types/api"; | ||
import { axiosInstance } from "./axios"; | ||
|
||
export const fetchProviders = (): Promise< | ||
PaginatedResponse<IdentityProvider[]> | ||
> => | ||
handleRequest(() => | ||
axios.get<PaginatedResponse<IdentityProvider[]>>(`/idps`), | ||
axiosInstance.get<PaginatedResponse<IdentityProvider[]>>(`/idps`), | ||
); | ||
|
||
export const fetchProvider = ( | ||
providerId: string, | ||
): Promise<IdentityProvider> => { | ||
return new Promise((resolve, reject) => { | ||
handleRequest<IdentityProvider[], ApiResponse<IdentityProvider[]>>(() => | ||
axios.get<ApiResponse<IdentityProvider[]>>(`/idps/${providerId}`), | ||
axiosInstance.get<ApiResponse<IdentityProvider[]>>(`/idps/${providerId}`), | ||
) | ||
.then(({ data }) => resolve(data[0])) | ||
.catch((error) => reject(error)); | ||
}); | ||
}; | ||
|
||
export const createProvider = (body: string): Promise<unknown> => | ||
handleRequest(() => axios.post("/idps", body)); | ||
handleRequest(() => axiosInstance.post("/idps", body)); | ||
|
||
export const updateProvider = ( | ||
providerId: string, | ||
values: string, | ||
): Promise<ApiResponse<IdentityProvider>> => | ||
handleRequest(() => | ||
axios.patch<ApiResponse<IdentityProvider>>(`/idps/${providerId}`, values), | ||
axiosInstance.patch<ApiResponse<IdentityProvider>>( | ||
`/idps/${providerId}`, | ||
values, | ||
), | ||
); | ||
|
||
export const deleteProvider = (providerId: string): Promise<unknown> => | ||
handleRequest(() => axios.delete(`/idps/${providerId}`)); | ||
handleRequest(() => axiosInstance.delete(`/idps/${providerId}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import { PaginatedResponse, ApiResponse } from "types/api"; | ||
import { handleRequest, PAGE_SIZE } from "util/api"; | ||
import { Schema } from "types/schema"; | ||
import axios from "axios"; | ||
import { axiosInstance } from "./axios"; | ||
|
||
export const fetchSchemas = ( | ||
pageToken: string, | ||
): Promise<PaginatedResponse<Schema[]>> => | ||
handleRequest(() => | ||
axios.get<PaginatedResponse<Schema[]>>( | ||
axiosInstance.get<PaginatedResponse<Schema[]>>( | ||
`/schemas?page_token=${pageToken}&page_size=${PAGE_SIZE}`, | ||
), | ||
); | ||
|
||
export const fetchSchema = (schemaId: string): Promise<Schema> => { | ||
return new Promise((resolve, reject) => { | ||
handleRequest<Schema[], ApiResponse<Schema[]>>(() => | ||
axios.get<ApiResponse<Schema[]>>(`/schemas/${schemaId}`), | ||
axiosInstance.get<ApiResponse<Schema[]>>(`/schemas/${schemaId}`), | ||
) | ||
.then(({ data }) => resolve(data[0])) | ||
.catch((error) => reject(error)); | ||
}); | ||
}; | ||
|
||
export const createSchema = (body: string): Promise<unknown> => | ||
handleRequest(() => axios.post("/schemas", body)); | ||
handleRequest(() => axiosInstance.post("/schemas", body)); | ||
|
||
export const updateSchema = ( | ||
schemaId: string, | ||
values: string, | ||
): Promise<ApiResponse<Schema>> => | ||
handleRequest(() => | ||
axios.patch<ApiResponse<Schema>>(`/schemas/${schemaId}`, values), | ||
axiosInstance.patch<ApiResponse<Schema>>(`/schemas/${schemaId}`, values), | ||
); | ||
|
||
export const deleteSchema = (schemaId: string): Promise<unknown> => | ||
handleRequest(() => axios.delete(`/schemas/${schemaId}`)); | ||
handleRequest(() => axiosInstance.delete(`/schemas/${schemaId}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters