Files
litlyx/dashboard/composables/useCustomRequest.ts
2024-06-01 15:27:40 +02:00

20 lines
501 B
TypeScript

export function createRequestOptions(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', sign: boolean, body?: Record<string, any>, headers: Record<string, string> = {}) {
const requestHeaders = sign ? signHeaders(headers) : headers;
let requestBody;
if (method === 'POST' || method == 'PUT' || method == 'PATCH') {
requestBody = body ? JSON.stringify(body) : undefined;
}
return {
method,
headers: requestHeaders,
body: requestBody
}
}