@adaskothebeast/typewriter-http-fetch
v10.0.2
Published
Fetch helpers for Typewriter runtime schemas.
Maintainers
Readme
Typewriter Fetch
Fetch helpers for Typewriter runtime schemas.
npm install @adaskothebeast/typewriter-http-fetchimport {
fetchJson,
serializeJsonBody,
} from '@adaskothebeast/typewriter-http-fetch';
const invoice = await fetchJson('/api/invoices/1', InvoiceSchema, undefined, {
registry: apiTypeRegistry,
});
await fetch('/api/invoices', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: serializeJsonBody(invoice, InvoiceSchema, {
registry: apiTypeRegistry,
}),
});fetchJson rejects non-success responses with TypewriterFetchError. A custom Fetch implementation can be provided through the fetch option.
