fetch-json v

A wrapper around Fetch just for JSON

Why would you fetch anything but json? ;)

fetch-json makes REST easy.  It's a lightweight JavaScript library to reduce the boilerplate code needed to make HTTP calls to JSON endpoints.

fetch-json automatically:
  1. Adds the HTTP header Content-Type: application/json to ensure the correct data type
  2. Runs .json() on the response
  3. Serializes the body payload with JSON.stringify()
  4. Appends params to the URL of GET requests
  5. Sets credentials to 'same-origin' (support user sessions in frameworks like Grails, Rails, PHP, Django, Flask, etc.)
  6. Converts the HTTP response to JSON if it's not already JSON (convenient for handling HTTP errors)
  7. Maps HTTP response headers from a HEAD request into a simple object
$ npm install fetch-json
fetchJson.get(url, params)
.then(handleData);