Access json api with ease
- Make XMLHttpRequests from the browser
- Automatic transforms for JSON data
Latest ✔ | Latest ✔ | Latest ✔ |
Using npm:
$ npm install requestapijs
Using yarn:
$ yarn add requestapijs
new Api().get(URLS.COMPANY)
.setHeader('authorization', localStorage.getItem('token'))
.success(
response => { #DO something },
)
.error(e => apiErrorHandler(e))
.done();
new Api().put(URLS.COMPANY, id, value)
.setHeader('authorization', localStorage.getItem('token'))
.success(
response => {
#Do something
},
).error(
error => { onError && onError(error); apiErrorHandler(error); },
).done();
new Api().post(URLS.COMPANY, value)
.setHeader('authorization', localStorage.getItem('token'))
.success(
response => {
COMPANY_REDUCER.fetchCompany();
onSuccess && onSuccess(response);
},
).error(
error => { onError && onError(error); apiErrorHandler(error); },
).done();