lfs-fetch

1.0.5 • Public • Published

mr-fetch polyfill

fetch() 函数用于请求接口,其中包含 fetch.get() / fetch.post() / fetch.push() / fetch.delete()。

Installation

npm install ms-fetch --save

const fetch = require('ms-fetch');

Usage

For a more comprehensive API reference that this polyfill supports, refer to https://github.com/hemiahwu/mr-fetch

Importing

Importing will automatically polyfill window.fetch and related APIs:

import 'ms-fetch';

GET JSON

fetch.get('http://jsonplaceholder.typicode.com/users').then(users => {
  console.log(users);
});

Post JSON

var users = {
  name: 'name',
  age: 'age'
};

fetch.post('/users', users).then(res => console.log(res));

PUT JSON

var users = {
  name: 'name',
  age: 'age'
};

fetch.put('/users/:id', users).then(res => console.log(res));

DELETE JSON

var users = {
  name: 'name',
  age: 'age'
};

fetch.delete('/users/:id').then(res => console.log(res));

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i lfs-fetch

    Weekly Downloads

    0

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    11.7 kB

    Total Files

    7

    Last publish

    Collaborators

    • lfs1403408257