npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-fetch-wrapper

v2.0.0

Published

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).

Downloads

22

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.