requestapijs
v2.1.10
Published
Access json api with ease
Readme
Request Api JS
Access json api with ease
Features
- Make XMLHttpRequests from the browser
- Automatic transforms for JSON data
Browser Support
|
|
|
--- | --- | --- |
Latest ✔ | Latest ✔ | Latest ✔ |
Installing
Using npm:
$ npm install requestapijsUsing yarn:
$ yarn add requestapijsExample
Get Request
new Api().get(URLS.COMPANY)
.setHeader('authorization', localStorage.getItem('token'))
.success(
response => { #DO something },
)
.error(e => apiErrorHandler(e))
.done();Put Request
new Api().put(URLS.COMPANY, id, value)
.setHeader('authorization', localStorage.getItem('token'))
.success(
response => {
#Do something
},
).error(
error => { onError && onError(error); apiErrorHandler(error); },
).done();Post
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();