New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

zero-fetch

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zero-fetch

Yet another convenient wrapper around fetch, for browser and node.js

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
7
250%
Maintainers
1
Weekly downloads
 
Created
Source

zero-fetch

Yet another convenient wrapper around fetch, for browser and node.js.

build status coverage npm dependencies

Why

  • fetch is good, but not easy enough
  • Minimal code for modern browsers. axios is still too big(5kb gzipped)
  • Minimal config
  • Focused to RESTFul API

Installing

Using npm:

$ npm i -D zero-fetch

Using cdn:

<script src="https://unpkg.com/zero-fetch/dist/index.js"></script>

Example

Performing a GET request

import zeroFetch from 'zero-fetch'

// Make a request for a user with a given id
zeroFetch('/user?id=12345')
.then(data => console.log(data))
.catch(error => console.log(error))

// Optionally the request above could also be done as
async getUser = () => {
  try {
    const data = await zeroFetch('/user', {
      data: {
        id: 12345
      }
    })
    console.log(data)
  } catch (error) {
    console.error(error)
  }
}

Smart Request Body

If data is a plain Javascript object, it will be encoded automatically and sent as search parameters, or request body, based on method and requestType.

Smart Search Parameters

When converting data to search parameters, nested objects are encoded to be understanded by express, so that req.query is same as data.

TODO: FormData application/x-www-form-urlencoded TODO: base64 encode inner Blob

  • data: the data to be sent as search parameters(GET) or the request body(other method).

Smart Response

Response body is automatically converted by proper method, based on Content-Type of response header. Supported types are:

  • application/json: .json
  • text/plain: .text
  • application/octect-stream: .blob

Keywords

fetch

FAQs

Package last updated on 22 Jun 2018

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