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

re-quests

v1.1.2

Published

Declarative Networking for React.

Downloads

6

Readme

re-quests

Declarative Networking for React.

npm npm

Quick Start

1. Install with NPM (or Yarn)

npm install --save re-quests

2. Fire up a network request by rendering the Request.

import Request from 're-quests';

...
render (
    <Request
        url='https://my-awesome-doma.in/me'
        onSuccess={this.myAwesomeResponseHandler}>
    
        <div> {/* use View for react-native */}
            <Request.Start>
                <MyAwesomeSpinner />
            </Request.Start>
            <Request.Success>
                <MyAwesomeContent content={this.state.content} />
            </Request.Success>
            <Request.Failure>
                <MyAwesomeErrorMessage />
            </Request.Failure>
        </div>
    </Request>
)

3. Handle the response the way you want.

myAwesomeResponseHandler = (response) => {
    // set a local state
    this.setState({
        content: response.data
    });
    
    // or dispatch an event
    // this.props.dispatch(myAwesomeAction(response.data));
}

Recipes

For common day problems & how to's, check out the Recipes page.

Disclosure

The library being used for sending requests is axios. Request component is just a declarative wrapper around it, exposing a few of the capabilities of axios.

Props

// `url` is the server URL that will be used for the request
url: PropTypes.string.isRequired,

// the http method is not required by axios &
// defaults to 'get' if not provided
method: PropTypes.oneOf(['get', 'post', 'put', 'patch', 'delete', 'head']),

// `headers` are custom headers to be sent
headers: PropTypes.object,

// `params` are the URL parameters to be sent with the request
// Must be a plain object or a URLSearchParams object
params: PropTypes.object,

// `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
// When no `transformRequest` is set, must be of one of the following types:
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
// - Browser only: FormData, File, Blob
// - Node only: Stream
data: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.object,
    PropTypes.instanceOf(ArrayBuffer),
    PropTypes.instanceOf(ArrayBufferView),
    PropTypes.instanceOf(URLSearchParams)
]),

// `paramsSerializer` is an optional function in charge of serializing `params`
// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
// default: function(params) { return Qs.stringify(params, {arrayFormat: 'brackets'}) }
paramsSerializer: PropTypes.func,

// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
// The last function in the array must return a string, an ArrayBuffer, FormData, or a Stream
transformRequest: PropTypes.arrayOf(PropTypes.func),

// `transformResponse` allows changes to the response data to be made before
// it is passed to then/catch
transformResponse: PropTypes.arrayOf(PropTypes.func),

// `validateStatus` defines whether to resolve or reject the promise for a given
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
// or `undefined`), the promise will be resolved; otherwise, the promise will be
// rejected.
// default: function (status) { return status >= 200 && status < 300; }
validateStatus: PropTypes.func,

// `maxRedirects` defines the maximum number of redirects to follow in node.js.
// If set to 0, no redirects will be followed.
// default: 5
maxRedirects: PropTypes.number,

// `timeout` specifies the number of milliseconds before the request times out.
// If the request takes longer than `timeout`, the request will be aborted.
timeout: PropTypes.number,

// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
// This will set an `Authorization` header, overwriting any existing
// `Authorization` custom headers you have set using `headers`.
// { username: 'janedoe', password: 's00pers3cret' }
auth: PropTypes.shape({
    username: PropTypes.string,
    password: PropTypes.string
}),

// `responseType` indicates the type of data that the server will respond with
// options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
// default: json
responseType: PropTypes.oneOf(['arraybuffer', 'blob', 'document', 'json', 'text', 'stream']),

// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
// default: 'XSRF-TOKEN'
xsrfCookieName: PropTypes.string,

// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
// default: 'X-XSRF-TOKEN'
xsrfHeaderName: PropTypes.string,


// callback fired just before the request is fired
onStart: PropTypes.func,

// callback fired after the response 
// comes back with status 2XX
onSuccess: PropTypes.func,

// callback fired after the response 
// comes back with status other 2XX
onFailure: PropTypes.func,

// callback fired when 
// something else goes wrong
onError: PropTypes.func,

// defer signals the Request component to not fire the 
// request as soon as ready instead construct the request and 
// wait for the manual trigger
// useful for cases when either the data is incomplete 
// or we want to wait for a CTA 
defer: PropTypes.bool,

// request can be tagged for enabling nested scenarios
// we might want to render a component based on 
// request sent way above the hierarchy of the component
// super grand parent component :P
tag: PropTypes.string

Limitations

Contribution

Any and all the contribution is welcome, providing it aligns with the interest of the project. Please make sure the commit messages follow the convention from the git commit template.