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 🙏

© 2025 – Pkg Stats / Ryan Hefner

reacthttp

v1.0.0

Published

An universal http module for react

Downloads

25

Readme

React Http

Build Status Coverage Status npm version bower version npm

React Http is built on top of fetch for browser side and node-fetch for server side. It provides an lightweight and fancy way to interact with backend REST API.

ReactHttp provides 5 basic method of REST API: POST, GET, PATCH, DELETE, PUT and new method sendFiles for upload file.

Installation

  • With npm: npm install reacthttp
  • With bower: bower install reacthttp
  • cdnjs

Usage

Basic usage

import ReactHttp from "reacthttp";

// Get method
ReactHttp.get("http://url")
 .then(data => {
   console.log(data);
 })
 .catch(error => {
   console.log(error);
 })
// Post method
ReactHttp.post("http://url", {foo: "bar"})
.then(data => {
  console.log(data);
})
.catch(error => {
  console.log(error);
})

// Upload file
var input = document.querySelector('input[type="file"]')
ReactHttp.sendFiles("http://url", {file: input.files[0]})
 .then(data => {
   console.log(data);
 })
 .catch(error => {
   console.log(error);
 })

With URL Search Params

UrlSearchParams supports all method of ReactHttp

import ReactHttp, { UrlSearchParams } from "reacthttp";
let searchParams = new UrlSearchParams();
searchParams.append("page", 1);
searchParams.append("order_by", "title")
// Send request
ReactHttp.get("http://url", searchParams)
    .then()

Custome Header

By default, ReactHttp's header

let defaultHeaderOptions = {  
  'Accept': 'application/json',
  'Content-Type': 'application/json'
};

You can add or modify global headers by setHeader function

import ReactHttp, { setHeader } from "reacthttp";
// custom header, if you want to override default header, just add it.
const customHeader = {
    Authorization: "Bearer askjdhui2343asdfjkhadsf",
    // Want to override
    Content-Type: ...
};
// change global header
setHeader(customHeader);
// Now ReactHttp will use new custom header

Modify header for only one request

import ReactHttp from "reacthttp";
const headerOptions = {
    Authorization: "Bearer askjdhui2343asdfjkhadsf",
};
ReactHttp.get("http://url", null, headerOptions)
    .then()

API

ReactHttp.get(url, urlSearchParams, customHeader);

ReactHttp.post(url, body, urlSearchParams, customHeader);

ReactHttp.put(url, body, urlSearchParams, customHeader);

ReactHttp.patch(url, body, urlSearchParams, customHeader);

ReactHttp.delete(url, urlSearchParams, customHeader);

ReactHttp.sendFiles(url, fileObj, urlSearchParams, customHeader);

setHeader(options);

options is a pure js object.

Default sendfiles Content-Type is multipart/form-data urlSearchParams is an instance of UrlSearchParams class

customHeader is an js object with key is a Http Header Field.

Examples

See examples

Liscense

npm