@ozylog/fetch
v1.2.0
Published
Simple fetch handler
Downloads
5
Readme
@ozylog/fetch
Installation
npm install @ozylog/fetch
Usage Example
fetch()
import {fetch} from @ozylog/fetch;
const response1 = await fetch('/users.html');
const body1 = await response.text();
const response2 = await fetch('/users.json');
const body2 = await response.json();
fetchJson()
// @flow
import {fetchJson} from @ozylog/fetch;
type ResponseType = {
status: number,
body: Object
};
const response1: ResponseType = await fetchJson('/user.json');
const response2: ResponseType = await fetchJson({
url: '/user.json',
method: 'POST',
body: JSON.stringify({hello: 'world'})
});
const response3: ResponseType = await fetchJson({
url: '/user.json',
method: 'GET',
query: {
ids: [1, 2],
country: 'AU'
}
}); // /user.json?ids[]=1&ids[]=2&country=AU
fetchGraphql()
// @flow
import {fetchGraphql} from @ozylog/fetch;
type ResponseType = {
status: number,
body: Object
};
const response1: ResponseType = await fetchGraphql({
url: '/graphql',
query: `{
user {
_id
firstName
lastName
email
}
}`,
variables: null
});
License
MIT