New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-fetchy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-fetchy

A simplified fetch api

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

logo

A simplified fetch API

→ Methods for each HTTP verb means no building request objects

→ API-level error handling means no checking status codes

→ Built-in response parsing means no additional checks and method calls

→ Optional one-time configuration means easy integration for your API

Install

$ npm i --save fetch-fetchy

Basic Usage

import { get, post } from 'fetch-fetchy';

/**
 * Create a user
 */
post('/user', formData)
  .then(onSuccess)
  .catch(onError)

/**
 * Fetch a user
 */
get('/user/hs9hsbs7')
  .then(onSuccess)
  .catch(onError)

Configuration

The default configuration is as follows:

{
	json: true,
	url: window.location.origin,
	headers: { 'Content-Type': 'application/json' },
	mode: 'cors'
}
json

If set to true, request data will automatically be converted to JSON.

url

The url to be used for api requests. When a route begins with /, it is assumed that the request is being made to the application's API. This means that you can define /user as the route instead of https://myapplicationdomain/user. If you set url to https://someotherdomain and specify /user as the route, the request will be made to https://someotherdomain/user. When the route does not begin with /, the full route will be used.

headers

The headers for requests.

mode

The request mode.


You may override these options for all requests by calling configure(). The default options will be overridden using Object.assign(). If you wish to apply options for a single request, just pass those options into that request.

import { configure } from 'fetch-fetchy';
/**
 * Configure fetch-fetchy
 */
const options = {
  url: 'https://myapi.com',
  headers: { Authorization: `Bearer ${jwt}`},
}
configure(options);

API Methods

get(route: String, options: Object) => Promise

post(route: String, body: *, options: Object) => Promise

put(route: String, body: *, options: Object) => Promise

patch(route: String, body: *, options: Object) => Promise

del(route: String, options: Object) => Promise

configure(options: Object) => Object

Keywords

FAQs

Package last updated on 11 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