Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-nice

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-nice

A helpful fetch wrapper

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

fetch-nice

Travis npm npm David

A thin wrapper around fetch to take care of some common use cases in the browser.

NB This does not handle polyfilling fetch. If you are using this in a browser that does not implement HTML5 Fetch API then you will need to polyfill with something like whatwg-fetch or it will not work.

Installation

npm i fetch-nice

Usage

The examples below are written using ES7 async/await for clarity. Of course you can still use fetch-nice without async/await since it returns a promise as per HTML5 fetch.

fetchNice assumes that your request is for JSON and sets headers accordingly. It also defaults to using fetch's credentials: 'include' setting so that any cookies are sent in order to make authenticated API requests.

The response object is JSON parsed automatically. If the response was a 204 (no content), fetch-nice returns undefined.

fetch-nice returns a rejected promise for error responses. If the error response contained a JSON body, this is added to the rejected Error. fetch-nice uses boom for it's errors.


import fetchNice from 'fetch-nice';

// make a GET request

const result = await fetchNice('http://myapi.com/user/me');


// make a POST request

const body = { name: 'Onion McOnionFace' };
const result = await fetchNice.post('http://myapi.com/users', { body });

// PUT and DELETE follow the same pattern.

Keywords

FAQs

Package last updated on 28 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc