@qite/tide-client
Version:
Frontend client for Tide
83 lines (74 loc) • 1.72 kB
text/typescript
export const post = async (
url: string,
apiKey: string,
body?: string | null,
token?: string,
signal?: AbortSignal,
languageCode?: string
): Promise<Response> => {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": apiKey,
Language: languageCode || "nl-BE",
Authorization: token ? `Bearer ${token}` : "",
},
credentials: "include",
body,
signal,
});
if (!response.ok) {
throw new Error(response.statusText);
}
return response;
};
export const patch = async (
url: string,
apiKey: string,
body?: string | null,
token?: string,
signal?: AbortSignal,
languageCode?: string
): Promise<Response> => {
const response = await fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Api-Key": apiKey,
Language: languageCode || "nl-BE",
Authorization: token ? `Bearer ${token}` : "",
},
credentials: "include",
body,
signal,
});
if (!response.ok) {
throw new Error(response.statusText);
}
return response;
};
export const get = async (
url: string,
apiKey: string,
token?: string,
signal?: AbortSignal,
languageCode?: string
): Promise<Response> => {
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
"Api-Key": apiKey,
Language: languageCode || "nl-BE",
"Accept-Language": languageCode || "nl-BE",
Authorization: token ? `Bearer ${token}` : "",
},
credentials: "include",
signal,
});
if (!response.ok) {
throw new Error(response.statusText);
}
return response;
};