setch
v3.0.0
Published
Simplest fetch wrapper
Downloads
1,518
Maintainers
Readme
Simplest fETCH wrapper I could come up with to reduce boilerplate code when using fetch
on a daily basis while keeping as much compatibility with standard as possible
features
- creating
setch
functions with default options - flexible status code checks with proper errors
- aliases to common content-type strings
install
npm i setch
usage
// basics, see docs for details
import { setch, makeSetch, mime } from 'setch'
// capture common parameters for reuse
const setchMyApi = makeSetch(
baseUrlString, // final url will be baseUrlString + urlString
{ headers: { accept: mime.json } }, // will be merged with options, headers too
200, // expected status, will throw if it isn't, can be overridden and flexible, see docs
)
// same as setch, but uses captured parameters too
const json = await setchMyApi(urlString, options).then(r => r.json())
docs
but there's not much to it really, have a look at source if you're curious :^)