Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.22 KB

README.md

File metadata and controls

59 lines (41 loc) · 1.22 KB

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');