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-rest-kit

v0.2.0

Published

wrap fetch to restful style

Downloads

16

Readme

react-rest-kit

wrap fetch to RESTful style

Why react-rest-kit

Flexible wrapper of fetch for RESTful api.

Usage

  • Create a rest client
import Rest from 'react-rest-kit';

const rest = new Rest({
  debug: true,
  mockRequire: require('./_mocks_'),  // api mock files location
  mockOptions: {  // api mock options, go to https://github.com/WhatAKitty/react-native-fetch-mock to find details
    delay: 200, // 200ms
    fetch: global.fetch,
    exclude: [
      'http://(.*)',
      'https://(.*)',
    ],
  },
  contentType: 'application/json',  // the body content type
  dataType: 'json',   // the accept data type
  exceptionHandler: ({ status, err }) => {    // global exceptionHandler
    if (status === 401 || status === 403) {
      dispatch({
        type: 'logout',
      });
    } else {
      notification.error(err.message);
    }
  },
});

export default rest;
  • Using rest client
import rest from './the/path/to/rest/file';

const testGET = async () => {
  const { data, err } = await rest.GET('url', {
    name: 'whatakitty',
  }, {
    qsStringifyOptions: {
      encodeURIComponent: uri => uri,     // with no encode
    },
  });
};
// => GET `url?name=whatakitty`

const testPOST = async () => {
  const { data, err } = await rest.POST('url', {
    name: 'whatakitty',
    sex: 'boy',
  });
};
// => POST `url` with parameter { name: 'wahtakitty', sex: 'boy' }

const testPUT = async () => {
  const { data, err } = await rest.POST('url', {
    id: '123abc',
    name: 'whatakittyNew',
  });
};
// => PUT `url` with parameter { id: '123abc', name: 'whatakittyNew' }

const testDELETE = async () => {
  const { data, err } = await rest.DELETE('url/123abc');
};
// => DELETE `url/123abc`

const testPATCH = async () => {
  const { data, err } = await rest.PATCH('url/123abc', {
    name: 'whatakittyNew',
  });
};
// => PATCH `url/123abc` with parameter { name: 'whatakittyNew }

Roadmap

  • [x] Basic RESTful style
  • [x] Global headers setting
  • [x] Dev mode(with React Fetch Mock)
  • [ ] Refactor code

LICENSE

MIT