https://github.com/samrocksc/howard
An isomorphic-fetch based library for making api calls super easy.
https://github.com/samrocksc/howard
Last synced: 10 months ago
JSON representation
An isomorphic-fetch based library for making api calls super easy.
- Host: GitHub
- URL: https://github.com/samrocksc/howard
- Owner: samrocksc
- License: mit
- Created: 2017-08-29T15:09:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-22T17:24:31.000Z (over 7 years ago)
- Last Synced: 2025-01-14T18:56:29.400Z (over 1 year ago)
- Language: JavaScript
- Size: 607 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
- awesome-phoenix - howard - isomorphic fetch wrapper of great reknown (Homegrown Open-Source Software)
README
# Howard The Duck
[](https://nodei.co/npm/howard/)
[](https://travis-ci.org/samrocksc/howard)
[](https://circleci.com/gh/samrocksc/howard)
[](https://coveralls.io/github/samrocksc/howard?branch=master)

I simplify life! If you are on a project that requires a lot of api Calls I can just handle the data retrieval in a quick and efficient manner! Set a simple config file of the base URL and start making easier REST calls!
Howard is basically a factory function for an [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) call that extracts JSON and returns it as a promise. Do whatever you want with the Promise, tag it in a chain.....tap it and use the results? Make what you need to happen with it!
## Examples!!!!
Including Howard:
```javascript
import howard, { withDefaults, json, text, arrayBuffer, blob, formData, buffer} from 'howard';
```
```javascript
json(howard('https://swapi.co/api/people/1/'))
.then((res) => {
/*
{
"name": "Luke Skywalker",
...
}
*/
})
```
Need Query Strings? put them in manually, or pass a param object!
```javascript
const paramString = '?format=wookiee';
json(howard(`https://swapi.co/api/people/1${paramString}`, { method: 'GET' }))
.then((res) => {
/*
{
"whrascwo": "Lhuorwo Sorroohraanorworc",
"acwoahrracao": "172",
"scracc": "77",
...
}
*/
})
```
Using a param:
```javascript
json(howard('https://swapi.co/api/people/1', { method: 'GET', params: { format: 'wookiee' } }))
.then((res) => {
return res;
})
```
If you need to set up a client with a default configuration, use the `withDefaults` method and specify a config object that gets merged with options for every request. In this example we also use async await:
```Javascript
const api = withDefaults(config);
json(api('/people/1/'))
.then((res) =>{
console.log('res', res)
})
async function withDefaultsRequest() {
let response = await json(api('/people/1/', { method: 'GET'}));
return response;
/*
{
"name": "Luke Skywalker",
...
}
*/
}
withDefaultsRequest();
```
**A Highly Opinionated Setup** - The goal of this setup would to create a lib style setup and return the fetch with the assumption that most of the app is going to be delivering JSON. This would apply to almost all use cases.
```Javascript
import { withDefaults, json } from 'howard';
const api = withDefaults({
url: 'http://api.url.com',
});
export function apiFetch(path, options = {}) {
return json(api(path, options));
}
```