Skip to content

SimplyBuilt/fetch-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fetch API

Build Status

Terser fetch API for JavaScript.

Examples

GET something:

Fetch.get('/something.json').then(success).catch(failure);

GET something else with same-origin credentials:

Fetch.get('/something-else.json', true).then(success).catch(failure);

GET something with headers

Fetch.get('/something', {
  headers: {
    'Accept': 'application/json',
    'X-Request-With': 'fetch'
  }
});

POST/PATCH some JSON data:

Fetch.post('/something.json', JSON.stringify({ user: {name: 'Simon' }), 'json');

Or PATCH/POST regular form data:

Fetch.patch('/something.json', 'user[name]=Simon', 'form');

POST/PATCH some other body type with same origin credentials:

Fetch.post('/something.json', btoa('hello'), 'application/base64', true);

POST/PATCH buffers:

var buffer = new ArrayBuffer(128);
var view   = new Int32Array(buffer);

for (var i = 0; i < view.length; i++)
  view[i] = Math.pow(i, 2);

Fetch.patch('/something.json', buffer, 'application/octet-stream');

About

🚣 fetch() API wrapper for JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published