shitzu

1.0.6 • Public • Published

Shitzu

An extremely helpful and tiny wrapper for the fetch api.

Yep, that's my dog

Basic usage example

import Api from 'shitzu';

Api.setEndpoint('www.yourapi.com');

let call;

try {
  call = await Api.post('/auth/signup', {
    email: 'foo@bar.com',
    password: 'johndoe'
  });
  // Response body = { status: 'OK', data: 'YOUR-TOKEN' }
  Api.setHeaders( {
    Authorization: `Bearer ${call.data}`
  } );
  call = await Api.get('/users/me');
  // Response body = { status: 'OK', data: { email: 'foo@bar.com' } }
}
catch( ERR ){
  console.error( ERR );
}

Setting custom headers

Api.setHeaders( {
  Authorization: 'Bearer [YOUR-TOKEN]',
  Accept: 'application/json'
} );

Changing mode

Api.setMode('no-cors|cors|same-origin');

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.6
    0
    • latest

Version History

Package Sidebar

Install

npm i shitzu

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

67.2 kB

Total Files

8

Last publish

Collaborators

  • alcmoraes89