0.33.0 • Published 1 year ago

rb-data-provider-json-server v0.33.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

MethodAPI call
getManyGET http://my.api.url/:resource
getOneGET http://my.api.url/:resource/:id
createOnePOST http://my.api.url/:resource
updateOnePATCH http://my.api.url/:resource/:id
updateManyPATCH http://my.api.url/:resource
deleteOneDELETE http://my.api.url/:resource/:id
deleteManyDELETE http://my.api.url/:resource

Options

NameDescriptionDefault
timeoutThe timeout (ms) for each single HTTP request attempt5000
retriesThe number of attempts before failing3
backoffThe incremental delay (ms) between request attempts500
clientA fetch-like HTTP client used to perform the requestsfetch
tokenGetterAn async function to get the bearer token to be usedundefined
contentTypeParserA function used to parse the content type of the request payload (if any)(data) => 'application/json; charset=UTF-8'
responseDataParserA sync function to extract the payload from the response payload(payload) => payload?.data \|\| payload
responseMetaParserA sync function to extract the meta details from the response payload (e.g. pagination data)(payload) => payload?.meta \|\| {}
responseErrorParserA (a)sync function to extract the details from an error response(res) => res?.statusText \|\| res?.status
querystringRendererA function to render the request querystringProvided renderQuerystring function
idempotentUpdateIf true, the PUT method will be used on update requestsfalse
cacheAn 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

0.33.0

1 year ago

0.32.0

1 year ago

0.31.0

1 year ago

0.30.2

1 year ago

0.30.1

1 year ago

0.30.0

1 year ago

0.29.1

2 years ago

0.29.0

2 years ago

0.28.1

2 years ago

0.28.0

2 years ago

0.27.0

2 years ago

0.26.0

2 years ago

0.25.1

2 years ago

0.25.0

3 years ago

0.24.0

3 years ago

0.21.0

4 years ago

0.20.0

4 years ago

0.19.1

4 years ago

0.23.0

4 years ago

0.22.0

4 years ago

0.19.0

4 years ago

0.18.0

4 years ago

0.17.0

4 years ago

0.16.0

4 years ago

0.13.0

4 years ago

0.14.0

4 years ago

0.15.0

4 years ago

0.11.0

4 years ago

0.12.0

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.1

4 years ago

0.8.2

4 years ago

0.8.0

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago