Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nox-client

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nox-client

This is a rest client for react

  • 0.0.12
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 15 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc