3.0.0 • Published 2 years ago

fetchit v3.0.0

Weekly downloads
26
License
MIT
Repository
github
Last release
2 years ago

fetchit

fetchit provides additional utilities for fetch that works in both Node and the browser.

Installation

yarn

yarn add fetchit

npm

npm install --save fetchit

Documentation

By default, fetchit works identically to fetch with the exception that it will throw a StatusCodeError for non-200 responses.

In addition to the standard fetch API, fetchit adds a few extra utilities:

fetchit.json

fetchit.json() accepts the same arguments as fetch, but rather than the full response object, it will return a JSON object:

const fetch = require('fetchit')
console.log('result', await fetch.json('https://httpbin.org/anything'))

fetchit.text

fetchit.text() accepts the same arguments as fetch, but rather than the full response object, it will return the response body as a string:

const fetch = require('fetchit')
console.log('result', await fetch.text('https://httpbin.org/robots.txt'))

options

fetchit supports additional options beyond what fetch provides by default:

query

You can pass in a query object to be formatted and tacked onto the URL as a query string:

const fetch = require('fetchit')
console.log('result', await fetch.json('https://httpbin.org/get', {
  date: Date.now(),
  boolean: true,
  string: 'string'
}))

form

You can pass in a form object and fetchit will setup an application/x-www-form-urlencoded request body:

const fetch = require('fetchit')
console.log('result', await fetch.json('https://httpbin.org/form', {
  method: 'POST',
  form: {
    date: Date.now(),
    boolean: true,
    string: 'string'
  }
}))

body

If you pass an object to body, fetchit will setup a application/json request body:

const fetch = require('fetchit')
console.log('result', await fetch.json('https://httpbin.org/form', {
  method: 'POST',
  body: {
    date: Date.now(),
    boolean: true,
    string: 'string'
  }
}))

Note: If you pass in a FormData instance as the value of body or you provide a Content-Type header, the standard fetch behavior will apply for body.

credentials

Unlike fetch, by default, fetchit will set credentials to same-origin.

License

fetchit was created by Shaun Harrison and is made available under the MIT license.

4.0.0-beta.1

2 years ago

4.0.0-beta.0

2 years ago

3.1.0-beta.0

2 years ago

3.0.0

3 years ago

3.0.0-beta.7

3 years ago

3.0.0-beta.5

3 years ago

3.0.0-beta.4

3 years ago

3.0.0-beta.6

3 years ago

3.0.0-beta.3

3 years ago

3.0.0-beta.2

4 years ago

3.0.0-beta.1

5 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.0

8 years ago