Files
perauset-e2e-mrfzphpz/e2e/tests/support/api-client.ts
2026-07-11 08:35:02 +02:00

59 lines
1.1 KiB
TypeScript

function buildHeaders(cookies?: string): Record<string, string> {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
Accept: 'application/json',
}
if (cookies) {
headers['Cookie'] = cookies
}
return headers
}
export async function apiGet(
url: string,
path: string,
cookies?: string
): Promise<Response> {
return fetch(`${url}${path}`, {
method: 'GET',
headers: buildHeaders(cookies),
})
}
export async function apiPost(
url: string,
path: string,
body: any,
cookies?: string
): Promise<Response> {
return fetch(`${url}${path}`, {
method: 'POST',
headers: buildHeaders(cookies),
body: JSON.stringify(body),
})
}
export async function apiPut(
url: string,
path: string,
body: any,
cookies?: string
): Promise<Response> {
return fetch(`${url}${path}`, {
method: 'PUT',
headers: buildHeaders(cookies),
body: JSON.stringify(body),
})
}
export async function apiDelete(
url: string,
path: string,
cookies?: string
): Promise<Response> {
return fetch(`${url}${path}`, {
method: 'DELETE',
headers: buildHeaders(cookies),
})
}