1.0.12 • Published 5 years ago

hw-api-fetch v1.0.12

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

hw-api-fetch

NPM JavaScript Style Guide

Install

npm install --save hw-api-fetch
or
yarn add hw-api-fetch

Usage

First you have to pass the properties of your api to the HWApiFetch component:

import HWApiFetch from 'hw-api-fetch'

const properties = {
  host: 'https://www.yourapi.com.br/api/',
  cookiesToHeader: [{ 
    key: 'authId',
    cookie: 'authentication'
  },
  'authorization'],
  beforeReturn: [
    res => {return {...res, test: true}}
  ],
  log: true,
  hwResponse: true
}

HWApiFetch.init(properties)

The properties are:

KeyTypeDescription
hoststringThe host of your api.
cookiesToHeaderarrayArray of objects with the format {key, cookie}. If is passed a string it will be presumed that the key and the cookie are equals. If these cookies exists in the browser, it will be send with all your requests.
beforeReturnarrayArray of functions to be applied before the data returns.
logbooleanLog api calls to the console. Default false.
hwResponsebooleanData comes with hwResponse format. Default false.
noContentTypebooleanRemove default content-type sended in the header. Default false.
fetchPropertiesobjectAdd properties to fetch options.

Then you can make the calls to your api:

import HWApiFetch from 'hw-api-fetch'

HWApiFetch.get('getUsers', {limit: 10}).then( response => ... )
HWApiFetch.post('newUser', {user: 'John', password: 'ILikeWaffles'}).then( response => ... )
HWApiFetch.put('editUser', {name: 'Not John', password: 'NewPassword'}).then( response => ... )
HWApiFetch.patch('editUser', {name: 'Not John'}).then( response => ... )
HWApiFetch.delete('deleteUser', {name: 'John'}).then( response => ... )

get, post, put, patch, delete params are:

ParamTypeDescription
pathstringThe path of your call.
dataobjectThe data that you want to send.

License

MIT © daniellrs

1.0.12

5 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago