# react-fetch-wrapper

> it a easy to use package for an fetch api call. api-call-wrapper will need one passing perameter which should contain url, method, data(optional).

Latest version **2.0.0** (published 2018-05-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-fetch-wrapper
pnpm add react-fetch-wrapper
yarn add react-fetch-wrapper
bun add react-fetch-wrapper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-05-27 |
| First published | 2018-05-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rajnish Katharotiya |
| Maintainers | rajnishkatharotiya |
| Keywords | apiCall, front-end, javascript, react, react-wrapper, react-fetch-wrapper, api-wrapper, api, call, fetch, wrapper |

## Links

- npm: https://www.npmjs.com/package/react-fetch-wrapper
- Repository: https://github.com/knovator/react-fetch-wrapper
- Homepage: https://github.com/knovator/react-fetch-wrapper#readme
- Issues: https://github.com/knovator/react-fetch-wrapper/issues
- npm.io page: https://npm.io/package/react-fetch-wrapper

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2018-05-27
- 1.0.7 — 2018-05-11
- 1.0.6 — 2018-05-11
- 1.0.5 — 2018-05-11
- 1.0.4 — 2018-05-11

## README

# react-fetch-wrapper
Make easy call API and make work faster. It has now functionalities like compatible with every method (GET, POST, PUT, DELETE and more.), direct option to send data while the use of the POST, PUT method, and have an option for an optional data as a query string parameter.

it's an easy to use package for a fetch API call. React-fetch-wrapper will need one passing parameter which would contain URL, method, data(optional), queryString parameters(optional).

# How to use: 

> For an use of react-fetch-wrapper start with installation.

```
npm install react-fetch-wrapper
```

> Check installation from package.json, And import 'apiCall' method from this wrapper into the project file.

> Now 'apiCall' require URL and METHOD. So use object like below:
```
import {apiCall} from '../api-call-wrapper';

//defult object for apiCall
let login = {url: '/route-name/', method: 'GET'};

//call
apiCall(login);

```

->> Send data on apiCall for methods 'PUT', 'POST'

> Store that data into one object and append it to the object with a name 'data' which we created for apiCall. 

```
//data object
let data = { username: 'user', password: 'user'};

//append with apicall with an name 'data'
login['data'] = data;
//call
apiCall(login);
```

->> Send extra data on apiCall as a query string parameter.

> Store that data into one object like above and append it to a created object with a name 'query'.
```
//query object
let query = { id: 5};

//append with apicall with an name 'query'
login['query'] = query;
//call
apiCall(login);
```

->> Use response and errors.
> do use of response after apiCall success with a ' then', and do use of error if apiCall failed with a 'catch'.

```
let data = { username : "john",
             password : "xyz" };
             
    login['data'] = data;      //optional: push data object into login object with 'data' key only.
    apiCall (login)            //use login object as a perameter of apiCall
    .then(data => console.log(error)) //response
    .catch(error => console.log(error)); //error on api call
    
```

->> Full Example of react-fetch-wrapper

```
import {apiCall} from 'react-fetch-wrapper';

//call object
let login = {url: '/login', method: 'POST'}

//data object
let data = {username: 'user', password: 'user'};

//query object 
let query = {api-token: 'JGHGJHGJHGJHGJ'};

login['data'] = data; //append data object
login['query'] = query; //append query object

//call
apiCall(login).then(response => console.log(response.json())).catch(error => console.log(error));

```

Happy coding.

---
_Source: https://npm.io/package/react-fetch-wrapper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
