Skip to content
Snippets Groups Projects
Commit b45ae1fe authored by Chif Gergő's avatar Chif Gergő
Browse files

Wrap axios query methods inside a hook

parent 6c8866e5
No related branches found
No related tags found
1 merge request!7update master to dev
import axios, { AxiosRequestConfig } from 'axios';
import { ApiRequest, RequestParams } from './types';
function userRestQueries(
// When a request needs more config like CancelToken, etc.
config?: AxiosRequestConfig,
): Record<string, <Data>(path: string) => ApiRequest<Data>> {
return {
get: <Data>(path: string) => (params: RequestParams) =>
axios.get<Data>(path, { ...config, ...params }),
post: <Data>(path: string) => (params: RequestParams) =>
axios.post<Data>(path, params.body ?? {}, { ...config, ...params }),
put: <Data>(path: string) => (params: RequestParams) =>
axios.put<Data>(path, params.body ?? {}, { ...config, ...params }),
delete: (path: string) => (params: RequestParams) =>
axios.delete(path, { ...config, ...params }),
};
}
export default userRestQueries;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment