PromucFlow_constructor/app/client/src/api/Api.ts
ChandanBalajiBP 888d9c0223
chore: Send default environmentId in header of all api call (#23745)
## Description
> Send unused_env as environmentId in all API header call.
>
>
#### PR fixes following issue(s)
Fixes #23766
>
#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)
>
>
>
## Testing
>
#### How Has This Been Tested?
This changes is w.r.t #1521 PR in EE. Which will be tested in
regression.
- [x] Regression
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flagx

#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-05-26 15:22:20 +05:30

108 lines
2.4 KiB
TypeScript

import type { AxiosInstance, AxiosRequestConfig } from "axios";
import axios from "axios";
import { REQUEST_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
import { convertObjectToQueryParams } from "utils/URLUtils";
import {
apiFailureResponseInterceptor,
apiRequestInterceptor,
apiSuccessResponseInterceptor,
blockedApiRoutesForAirgapInterceptor,
} from "@appsmith/api/ApiUtils";
//TODO(abhinav): Refactor this to make more composable.
export const apiRequestConfig = {
baseURL: "/api/",
timeout: REQUEST_TIMEOUT_MS,
headers: {
"Content-Type": "application/json",
},
withCredentials: true,
};
const axiosInstance: AxiosInstance = axios.create();
const requestInterceptors = [
blockedApiRoutesForAirgapInterceptor,
apiRequestInterceptor,
];
requestInterceptors.forEach((interceptor) => {
axiosInstance.interceptors.request.use(interceptor as any);
});
axiosInstance.interceptors.response.use(
apiSuccessResponseInterceptor,
apiFailureResponseInterceptor,
);
class Api {
static get(url: string, queryParams?: any, config: AxiosRequestConfig = {}) {
return axiosInstance.get(url + convertObjectToQueryParams(queryParams), {
...apiRequestConfig,
...config,
});
}
static post(
url: string,
body?: any,
queryParams?: any,
config: AxiosRequestConfig = {},
) {
return axiosInstance.post(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static put(
url: string,
body?: any,
queryParams?: any,
config: AxiosRequestConfig = {},
) {
return axiosInstance.put(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static patch(
url: string,
body?: any,
queryParams?: any,
config: AxiosRequestConfig = {},
) {
return axiosInstance.patch(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static delete(
url: string,
queryParams?: any,
config: AxiosRequestConfig = {},
) {
return axiosInstance.delete(url + convertObjectToQueryParams(queryParams), {
...apiRequestConfig,
...config,
});
}
}
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
export default Api;