Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
/ fetch-22 Public archive

GET and POST JSON with less code and more convention.

License

Notifications You must be signed in to change notification settings

cucumber-ltd/fetch-22

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Fetch-22

GET and POST JSON with less code and more convention.

First, instantiate it:

const fetch = window.fetch.bind(window) // require('node-fetch')
const baseUrl = 'http://localhost:9988'
const fetch22 = new Fetch22({ baseUrl, fetch })

Second, use it:

// GET
const obj = await fetch22.get('/foo')

// POST
await fetch22.post('/foo', { bar: 'zap' })

get throws an error when the response isn't 200. post throws an error when the response isn't 201. The error contains the response body as text as well as the actual status code.

That's what we need 22% of the time. For the remaining 78% of cases, don't use Fetch-22.

About

GET and POST JSON with less code and more convention.

Resources

License

Stars

Watchers

Forks

Packages

No packages published