0.4.2 • Published 3 years ago

backpack-fetch v0.4.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

backpack-fetch

A Fetch wrapper utility for use with Backpack API.

Basic usage:
import api from 'backpack-fetch';
Example GET request:
const res = await api.get('/books/1234');
if (res.error) return console.log(res.error);
const books = res.data;

The res object returned in the above example is like this:

{
	status: 200,
	data: [ array of book objects ],
	error: null
 }
Example POST request:
const payload = { username: 'billgates', password: 'win95roolz' };
const res = await api.post('/getTokenWithPassword', payload);
if (res.error) return console.log(res.error);
const loggedInUser = res.data;

This time, the res object returned also contains a token (assuming this API route was written to include one).

{
 status: 200,
 data: { user object },
 error: null,
 token: 'abcdefg123456.abcdefg123456.abcdefg123456'
}

Whenever a token is returned, it is automatically saved to the client's local storage as 'token'.

...and whenever a token exists in localstorage, it will always be sent in the HTTP headers along

with every request. For example, the original example api.get('/books/1234') would have included

the JSON webtoken if one existed in localstorage.

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago