[Glitch] Proposal: a modern & typed way of writing Redux actions doing API requests

Port 10ec421dd4 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Renaud Chaput
2024-05-23 11:50:13 +02:00
committed by Claire
parent 51631c785f
commit 8d6058b40a
14 changed files with 281 additions and 125 deletions

View File

@@ -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;
}