0.0.23 • Published 6 years ago
fetchin v0.0.23
Fetchin
Install
yarn add fetchin
Fetchin assumes that fetch()
is globally available, install isomorphic-fetch
as well (not needed for React Native).
Quick start
import 'isomorphic-fetch';
import { get } from 'fetchin';
get('https://api.bitfinex.com/v2/tickers', {
params: { symbols: 'tBTCUSD' }
})
.then(res => console.log(res[0][7]))
.catch(err => console.log(err.message));
Usage
import { get, post } from 'fetchin';
// make a simple get request, promise-based, returns parsed json by default (can be modified)
await get('https://foo');
// passing params, url encoding is handled for you
await get('https://foo', { params: { bar: 123 } }); // https://foo?bar=123
// one base, multiple endpoints
const base = 'https://foo';
await get('/bar', { base }); // https://foo/bar
await get('/baz', { base }); // https://foo/baz
// no need for template strings, use args
await get('https://foo/{bar}', { args: { bar: 123 } }); // https://foo/123
await get('https://foo/{bar}/{baz}', { args: { bar: 123, baz: 456 } }); // https://foo/123/456
// response is not json?
await get('https://foo', { json: false });
// tweak/pass any other fetch() opts
await get('https://foo', { opts: { headers: { bar: 'baz' } } });
// make a simple post request, same api as get with an additional body option
await post('https://foo', { body: { bar: 123 } });
// Content-Type by default is `application/json`, body is stringified, to overwrite utilize opts
await post('https://foo', {
opts: { headers: { 'Content-Type': 'foo/bar' }, body: 'not json' }
});
// need access to the raw response?
await get('https://foo', { ref: true }); // returns { data, ref }
0.0.23
6 years ago
0.0.22
6 years ago
0.0.21
6 years ago
0.0.20
6 years ago
0.0.19
6 years ago
0.0.18
6 years ago
0.0.17
6 years ago
0.0.16
6 years ago
0.0.15
6 years ago
0.0.14
6 years ago
0.0.13
6 years ago
0.0.12
6 years ago
0.0.11
6 years ago
0.0.10
6 years ago
0.0.9
6 years ago
0.0.8
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago