Fake JSON API
A small package that intercepts AJAX requests and responds with data stored locally in IndexedDB. It attempts to fake an actual JSON API.
Setup
Install the package:
npm i fake-json-api
or
yarn add fake-json-api
Import it in your code:
or
const api =
Configure the database:
api
Uses Dexie.js stores syntax to define the schema
Add some data:
api
Start it intercepting requests:
api
Make a request:
Available endpoints would be:
- GET
/posts
- POST
/posts
- GET
/posts/:id
- PUT
/posts/:id
- DELETE
/posts/:id
Relational data
Works with dexie-relationships for relational data. So for example if you want to add users to posts:
api api
Users would now be nested in posts, and each user object would have an array of nested posts.
Available endpoints would be:
-
GET
/posts
-
POST
/posts
-
GET
/posts/:id
-
PUT
/posts/:id
-
DELETE
/posts/:id
-
GET
/users
-
POST
/users
-
GET
/users/:id
-
PUT
/users/:id
-
DELETE
/users/:id