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

rb-data-provider-json-server

v0.33.0

Published

A Restboard data provider for JSON REST server

Downloads

21

Readme

rb-data-provider-json-server

A Restboard data provider for JSON REST server

Node.js CI

Getting started

import createProvider from "rb-data-provider-json-server";

const provider = createProvider("https://jsonplaceholder.typicode.com");

provider
  .getMany("posts")
  .then((posts) => console.log(posts))
  .catch((err) => console.error(err));

Additional options can be configured during the data provider construction:

const provider = createProvider("https://jsonplaceholder.typicode.com", {
  timeout: 3000,
  retries: 5,
  backoff: 300,
});

REST Dialect

| Method | API call | | ------------ | ---------------------------------------- | | getMany | GET http://my.api.url/:resource | | getOne | GET http://my.api.url/:resource/:id | | createOne | POST http://my.api.url/:resource | | updateOne | PATCH http://my.api.url/:resource/:id | | updateMany | PATCH http://my.api.url/:resource | | deleteOne | DELETE http://my.api.url/:resource/:id | | deleteMany | DELETE http://my.api.url/:resource |

Options

| Name | Description | Default | | --------------------- | ----------------------------------------------------- | ----------- | | timeout | The timeout (ms) for each single HTTP request attempt | 5000 | | retries | The number of attempts before failing | 3 | | backoff | The incremental delay (ms) between request attempts | 500 | | client | A fetch-like HTTP client used to perform the requests | fetch | | tokenGetter | An async function to get the bearer token to be used | undefined | | contentTypeParser | A function used to parse the content type of the request payload (if any) | (data) => 'application/json; charset=UTF-8' | | responseDataParser | A sync function to extract the payload from the response payload | (payload) => payload?.data \|\| payload | | responseMetaParser | A sync function to extract the meta details from the response payload (e.g. pagination data) | (payload) => payload?.meta \|\| {} | | responseErrorParser | A (a)sync function to extract the details from an error response | (res) => res?.statusText \|\| res?.status | | querystringRenderer | A function to render the request querystring | Provided renderQuerystring function | | idempotentUpdate | If true, the PUT method will be used on update requests | false | | cache | An optional cache object to store request responses. Should implement the following API: has(reqId), get(reqId), set(reqId,res) | undefined |

Test

npm test

Contribute

If you want, you can also freely donate to fund the project development:

Donate

Have you found a bug?

Please open a new issue on:

https://github.com/restboard/rb-data-provider-json-server/issues

Acknowledgements

This project is inspired by:

License

Copyright (c) Emanuele Bertoldi

MIT License