Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Latest commit

 

History

History
67 lines (55 loc) · 1.57 KB

README.md

File metadata and controls

67 lines (55 loc) · 1.57 KB

Request Api JS

Access json api with ease

Features

Browser Support

Chrome Firefox Safari
Latest ✔ Latest ✔ Latest ✔

Installing

Using npm:

$ npm install requestapijs

Using yarn:

$ yarn add requestapijs

Example


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