npm.io
1.0.5 • Published 5 years ago

he-fetch

Licence
MIT
Version
1.0.5
Deps
1
Size
2 kB
Vulns
23
Weekly
0

he-fetch polyfill

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

Installation

npm install he-fetch

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

Importing

Importing will automatically polyfill window.fetch and related APIs:

import 'he-fetch';
GET JSON
fetch.get('http://jsonplaceholder.typicode.com/users').then(res => {
  console.log(res.data);
});
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));

Keywords