react-server-request
v1.1.1
Published
it is a simple way to fetch data , get data , put data , delete data from server site using API
Downloads
6
Readme
react-server-request
react-server-request
Browser Support
| | | | | | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
Installing
Using npm:
$ npm i react-server-request
Using bower:
$ bower i react-server-request
Using yarn:
$ yarn add react-server-request
use react-server-request simply:
// file name API.js
import {Request} from 'react-server-request'
export default new Request('here will be main path')
// this is like ----->
// const API = new Request('https://jsonplaceholder.typicode.com')
// get request for loading data
// get request for loading data
import {API} from './api'
API.get('/here will be get request path')
// this is like ----->
// const API = new Request('/users')
.then(res=>console.log(res))
.catch(function (error) {
console.log(error);
import {API} from './api'
API.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
import {API} from './api'
API.delete('/user')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
import {API} from './api'
API.put('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});