refactor API calls and routers

This commit is contained in:
2026-04-04 18:27:45 +02:00
parent 229edd42e9
commit c14864aa29
7 changed files with 141 additions and 109 deletions
+27
View File
@@ -0,0 +1,27 @@
import axios, {AxiosRequestConfig} from "axios";
export const http = axios.create({
withCredentials: true,
});
export async function getJson<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
const response = await http.get<T>(url, config)
return response.data
}
export async function getText(url: string, config?: AxiosRequestConfig): Promise<string> {
const response = await http.get<string>(url, {
...config,
responseType: "text",
})
return response.data
}
export async function postJson<TRequest, TResponse>(url: string, body: TRequest, config?: AxiosRequestConfig): Promise<TResponse> {
const response = await http.post<TResponse>(url, body, config)
return response.data
}
export async function postVoid<TRequest = undefined>(url: string, body?: TRequest, config?: AxiosRequestConfig): Promise<void> {
await http.post(url, body, config)
}