UNPKG

fetchbee

Version:

A lightweight JS library to simplify all kinds of API calls.

14 lines (13 loc) 359 B
export function postFetchWithMethod(method, url, body, options = {}) { return fetch(url, { method, headers: { "Content-Type": "application/json", ...options.headers, }, body: JSON.stringify(body), }).then(async (res) => { if (!res.ok) throw new Error(`${method} Error: ${res.status}`); return await res.json(); }); }