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

xfetch-js

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xfetch-js

> A extremely simple fetch extension for modern browsers inspired by [sindresorhus/ky](https://github.com/sindresorhus/ky). > > Which aims to be as small as possible and easy to use.

  • 0.0.8
  • Source
  • npm
  • Socket score

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

xfetch-js

A extremely simple fetch extension for modern browsers inspired by sindresorhus/ky.

Which aims to be as small as possible and easy to use.

Build Status npm

Examaple

// get with query string
xf('https://postman-echo.com/get/', { qs: { foo: 'bar' } })
  .json()
  .then(console.log)

// post form
xf.post('https://postman-echo.com/post', { form: { foo: 'bar' } })
  .json()
  .then(console.log)

// post json with transforms
xf.post('https://postman-echo.com/post', { json: { foo: 'bar' } })
  .json(r => r.data)
  .then(console.log)

// custom base, default base in browser is document.baseURI
const xf2 = xf.base('https://postman-echo.com/')
xf2.get('/get')
  .then(console.log)

// HTTPError
xf.get('https://postman-echo.com/404')
  .catch(e => {
    assert(e instanceof xf.HTTPError)
    console.log(e.response)
  })

With node

const xf = require('xfetch-js').create(require('node-fetch'))

xf('https://postman-echo.com/get/', { qs: { foo: 'bar' } })
  .json()
  .then(console.log)

Node version must be greater than 10

Otherwise, you will get an error about global.URL,global.URLSearchParams is undefined.

Of course, you can polyfill them by youself to use this module.

Main differences bewteen fetch and XFetch.js

  • credentials is set to same-origin by default.
  • throws error when response.ok is not true
  • Some useful methods to call, such as get,post and so on...
  • Support some simple serialization, including json,urlencoded and querystring

FAQs

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

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