🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

efetch

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

efetch

extend the whatwg fetch, makes it easier to use

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

License

efetch

extend the whatwg fetch - fetch spec, makes it easier to use.

document

  • config - set options

  • set() - set http header

  • send() - send body data

  • query() - set query string

  • append() - append form data

  • text() - convert response body to string

  • json() - convert response body to object

  • default options

{
  mode: 'cors',
  cache: 'no-cache',
  credentials: 'same-origin'
}

Usage

efetch.get(url, options)
  .config({
    credentials: 'omit'
  })
  .query({
    type: 1
  })
  .query({
    name: 'hello'
  })
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

// get json body

efetch.get(url, options)
  .query({
    type: 1
  })
  .send({
    name: 'hello'
  })
  .json()
  .then(function(data) {
    // response body
  })
  .catch(function(err) {
    // ...
  })

// get text body

efetch.get(url, options)
  .query({
    type: 1
  })
  .send({
    name: 'hello'
  })
  .text()
  .then(function(data) {
    // response body
  })
  .catch(function(err) {
    // ...
  })

// send json

efetch.post(url, options)
  .send({
    type: 1
  })
  .send({
    name: 'hello'
  })
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

// send urlencoded

efetch.post(url, options)
  .send('type=1')
  .send('name=hello')
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

// send urlencoded

efetch.post(url, options)
  .set('content-type', 'application/x-www-form-urlencoded')
  .send({
    type: 1,
    name: 'hello'
  })
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

// set header

efetch.post(url, options)
  .set({
    'content-type': 'application/json'
  })
  .send({
    type: 1
  })
  .send({
    name: 'hello'
  })
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

// send form (upload file)

efetch.post(url, options)
  .append({
    filename: 'user.png'
  })
  .append({
    file: document.querySelector('input[type="file"]')files[0]
  })
  .then(function(res) {
    // fetch response
  })
  .catch(function(err) {
    // ...
  })

License

MIT

Keywords

extend

FAQs

Package last updated on 04 Jun 2015

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