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

nox-client

v0.0.12

Published

This is a rest client for react

Downloads

4

Readme

Nox Client

NPM Greenkeeper badge CircleCI Coverage Status

Description

Nox is a REST client for React. It is inspired from the apollo client, especially in its usage

Warning : This is a very early WIP !

Background

This package is inspired by React Apollo, because I found the usage quite nice in the front end, but I was using a REST API, I thought it'd be a good idea to do so ... As for the name, it's my dog's

Installation

To install the module, simply enter the following command :

# Yarn
$ yarn install nox
# Npm
$ npm install nox --save

Usage

Provider

In order to use the client, you need to wrap your application inside a NoxProvider, here is an example :

import React from 'react'
import { NoxProvider } from 'nox'

import App from './App'

export default () => (
  <NoxProvider options={{
    baseURL: 'http://localhost:1337'
  }}>
    <App />
  </NoxProvider>
)

Available options

The provider accepts the following options :

  • baseURL: Your API base URL, with the scheme
  • timeout: Default timeout for request
  • headers: Default headers for the request
  • cacheTimeout: The time (in milleseconds) that the object should be keep in cache (Default 10 minutes)

Components

To use the client, you need to wrap your component using the noxConnect function, just like in the following example

import React, { Component } from 'react'
import { map } from 'lodash'
import { noxConnect } from 'nox'

import Product from './Product'

class Display extends Component {
  render() {
    const { noxData } = this.props;

    if (noxData.loading) {
      return (
        <h1>Loading</h1>
      )
    }

    const { data } = noxData
    return (
      <div>
        <div>
          {map(data, product => (<Product {...product} key={product._id}/>))}
        </div>
      </div>
    );
  }
}

export default noxConnect({
  method: 'GET',
  path: '/products'
})(Display)

Available options

The available options are :

  • method : The HTTP Verb to use, case unsensitive
  • path : The path to request
  • cache : A boolean to indicate to use cache or not (default to true)
  • subscribe : Should the request subscribe to the response (default to true). Useful for not GET request
  • headers : The request headers
  • pollInterval : Should be pulled regularly
  • cacheTimeout : The specfic cache timeout for the request

Accessing the client directly

To access the REST client directly, you can wrap your component with the withNoxClient function, which will make the client accessible in the component's props as noxClient

import React from 'react'
import { withNoxClient } from 'nox'

class ComponentWithClient extends React.Component {
  render () {
    // Access the client in this.props.client
    return (
      <p>Client is accessible</p>
    )
  }
}

export default withNoxClient(ComponentWithClient)

Who is Nox ?

Nox de Valvygne is my german shepherd dog, he is used to come to the office, so this package is a little tribute for him

Nox in the office

See also

TODO

  • Make tests
  • ...