Skip to content

Instantly share code, notes, and snippets.

View Klekum's full-sized avatar

Dominique Klevinghaus Klekum

  • Klinikum der Universität München - MIT @KUMteamIM
View GitHub Profile
@Klekum
Klekum / api.ts
Created October 27, 2022 07:13
Drop-in replacement for Axios json handler using Fetch API
const API_BASE = "/api/v1";
export function sendRequest(endpoint: string, method: string, data?: any) {
const reqParams: RequestInit = { method }
if (data) reqParams.body = new URLSearchParams(data)
return new Promise((resolve, reject) => {
fetchAuth(API_BASE + endpoint, reqParams).then(jsonResponse).then(resolve).catch(reject)
})
}