Proposal: a modern & typed way of writing Redux actions doing API requests (#30270)
This commit is contained in:
parent
3a862439df
commit
10ec421dd4
14 changed files with 281 additions and 125 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { AxiosResponse, RawAxiosRequestHeaders } from 'axios';
|
||||
import type { AxiosResponse, Method, RawAxiosRequestHeaders } from 'axios';
|
||||
import axios from 'axios';
|
||||
import LinkHeader from 'http-link-header';
|
||||
|
||||
|
@ -58,3 +58,17 @@ export default function api(withAuthorization = true) {
|
|||
],
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiRequest<ApiResponse = unknown>(
|
||||
method: Method,
|
||||
url: string,
|
||||
params?: unknown,
|
||||
) {
|
||||
const { data } = await api().request<ApiResponse>({
|
||||
method,
|
||||
url,
|
||||
params,
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue