Notable Pottery Manufacturer
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

howard

1.0.1 • Public • Published

Howard The Duck

NPM

Build Status

Coverage Status

howard

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 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:

import howard, { withDefaults, json, text, arrayBuffer, blob, formData, buffer} from 'howard';
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!

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:

  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:

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();

install

npm i howard

Downloadsweekly downloads

34

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability