Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 5x 4x 4x 2x 2x 2x 1x 1x | const createHttpHandlerWithMethod = (method) => async (url, options) => {
const response = await fetch(url, { ...options, method });
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
Eif (response.status === 200) {
return response.headers.get('Content-Type') === 'application/json'
? response.json()
: response.text();
}
return undefined;
};
const http = {
get: createHttpHandlerWithMethod('GET'),
post: createHttpHandlerWithMethod('POST'),
put: createHttpHandlerWithMethod('PUT'),
patch: createHttpHandlerWithMethod('PATCH'),
delete: createHttpHandlerWithMethod('DELETE'),
};
export default http;
|