Optional
body?: string | FormDataBody of the request of type given in the "Content-Type" header.
Optional
headers?: Record<string, string> | HeadersHeaders that should be appended to the request.
Optional
redirect?: "follow" | "manual"Whether we should automatically handle the redirections or do it by hand.
import type { PawnoteFetcher } from "pawnote";
// With the `fetch()` builtin, in TypeScript.
// This is actually the code for the default fetcher.
const fetcher: PawnoteFetcher = async (url, options) => {
const response = await fetch(url, {
method: options.method,
headers: options.headers,
redirect: options.redirect,
// Setting a body is not allowed on GET requests.
body: (options.method === "GET") ? void 0 : options.body
});
return {
headers: response.headers,
text: () => response.text(),
json: <T>() => response.json() as T
};
};
A fetcher that looks like the Fetch API so every fetcher applied to Pawnote will have the same API and should output the same thing.