UNPKG

react-http-client

Version:

A httpClient for react frontend app using which you can make api calls

79 lines (63 loc) 1.46 kB
## HTTP Client for React Apps ### Installing `npm install react-http-client` ### Uses The handler takes 3 args 1. URL 2. Body : default {} 3. Headers : default {} ```js import httpClient from 'react-http-client'; // or const httpHandler = require('react-http-client'); const postResponse = await httpHandler.post( // url 'http://dummy.restapiexample.com/api/v1/create', // body { name: 'test', salary: '123', age: '23', } // headers if any ); console.log(postResponse); // { // status: 'success', // data: { name: 'test', salary: '123', age: '23', id: 66 } // } const getResponse = await httpHandler.get( 'http://dummy.restapiexample.com/api/v1/employees' ); console.log(getResponse); // { // status: 'success', // data: [ // { // id: '1', // employee_name: 'Tiger Nixon', // employee_salary: '320800', // employee_age: '61', // profile_image: '' // }, // { // id: '2', // employee_name: 'Garrett Winters', // employee_salary: '170750', // employee_age: '63', // profile_image: '' // }, // { // id: '3', // employee_name: 'Ashton Cox', // employee_salary: '86000', // employee_age: '66', // profile_image: '' // }, // ... // ... // ] // } ``` You can also use inbuilt fetch to do the same but this will provide you a simple interface with which you can make calls easily. -- Thanks