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-http-request

v2.0.0

Published

React component exposes network request functionality

Downloads

683

Readme

React-http-request

npm npm

React component exposes network request functionality

Useful component to perform a network request and parse the response using superagent module.

Installation

Using npm:

npm install --save react-http-request

Supposing a CommonJS environment, you can simply use the component in this way:

import React, { Component } from 'react';
import Request from 'react-http-request';

export default class App extends Component {
  render() {
    return (
      <Request
        url='https://api.github.com/users/mbasso'
        method='get'
        accept='application/json'
        verbose={true}
      >
        {
          ({error, result, loading}) => {
            if (loading) {
              return <div>loading...</div>;
            } else {
              return <div>{ JSON.stringify(result) }</div>;
            }
          }
        }
      </Request>
    );
  }
}

Documentation

This component use its props to perform a network request based on superagent. Here you can find all details about usage.

Callback

The prop children of this component would be a function that takes an object as parameter. This object is composed by 3 properties:

|Property |Description | |---|---| |error |Contains superagent request error, see this for more information | |result |Contains superagent request response, see this for more information | |loading |True or false, indicates if request is loading or is finished |

This function will be triggered the first time immediately and second time when request is complete. You can see an example to clarify this concept in Installation section.

Props

Here is the list of the props used by the component, as we said before, it is based on superagent, so, you will find the complete documentation in its site, you will find a link for most props.

|Property |Type |Description | |---|---|---| |url |String |Request url | |method |String |Request method: get, head, post, put, delete | |children |function({ error, result, loading }): return node |Function explained above in "callback" section | |type |String |Header Content-Type. docs | |accept |String |Header Accept. docs | |timeout |Number |A timeout after which an error will be triggered. docs | |verbose |Boolean |If true, error messages will automatically be logged to the console | |query |Object or String |Query parameter. docs | |send |Object or String |Post parameter. docs | |headers |Object |Request header. docs | |auth |{ user: '', pass: '' } |Basic authentication. docs | |withCredentials |Boolean |Enables the ability to send cookies from the origin, however only when "Access-Control-Allow-Origin" is not a wildcard ("*"), and "Access-Control-Allow-Credentials" is "true". docs | |buffer |Boolean |To force buffering of response bodies as result.text. docs | |attach |Array of { name: '', path: '', filename: '' } |Attach files. docs | |fields |Array of { name: '', value: '' } |Much like form fields in HTML, you can set field values. docs | |onRequest |function(request): return request |Function that will be called before sending the request. It accept as parameter the request itself and must return the request. This means that you can manually modify the request that will be sent. |

Author

Matteo Basso

Copyright and License

Copyright (c) 2016, Matteo Basso.

React-http-request source code is licensed under the MIT License.