setch
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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

generated typedoc

but there's not much to it really, have a look at source if you're curious :^)

Package Sidebar

Install

npm i setch

Weekly Downloads

120

Version

3.0.0

License

ISC

Unpacked Size

18.6 kB

Total Files

24

Last publish

Collaborators

  • qwemaze