All Projects → bahmutov → json-server-reset

bahmutov / json-server-reset

Licence: other
Reset middleware for json-server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to json-server-reset

Jarvis
APL-based web service framework supporting JSON or REST
Stars: ✭ 17 (+30.77%)
Mutual labels:  json-server
resetusb
List USB devices and reset a USB device from the command line
Stars: ✭ 79 (+507.69%)
Mutual labels:  reset
goreset
Generates automatically a Reset() method
Stars: ✭ 28 (+115.38%)
Mutual labels:  reset
django-reset-password
This project is an implementation example for reset password of django
Stars: ✭ 21 (+61.54%)
Mutual labels:  reset
DummyJSON
DummyJSON provides different types of REST Endpoints filled with JSON data which you can use in developing the frontend with your favorite framework and library without worrying about writing a backend.
Stars: ✭ 213 (+1538.46%)
Mutual labels:  json-server
embedio-extras
Additional Modules showing how to extend EmbedIO.
Stars: ✭ 43 (+230.77%)
Mutual labels:  json-server
Tinyreset
Tiny CSS reset for the modern web
Stars: ✭ 251 (+1830.77%)
Mutual labels:  reset
http-interceptors
The Web apps in this monorepo make HTTP requests and require uniform consistency in how they are executed and handled. This monorepo demonstrates the same app written with Angular and with Svelte. Each app uses HTTP interceptors. The Angular app uses HttpClient and its interceptors while the Svelte app uses Axios and its interceptors.
Stars: ✭ 46 (+253.85%)
Mutual labels:  json-server
json-now
$ json-now - Launch an API Server to serve data from a JSON, JS file or faker data with HTTPS support. Based on json-server.
Stars: ✭ 18 (+38.46%)
Mutual labels:  json-server
fake-rest-api-nodejs
Fake REST API using NodeJS + JSON Server
Stars: ✭ 45 (+246.15%)
Mutual labels:  json-server
vue-netflix-clone
The repository contains the clone of the application with millions of active users in real life.
Stars: ✭ 32 (+146.15%)
Mutual labels:  json-server
cruise
A Continuous Integration (CI) management system homework from Thought Works
Stars: ✭ 13 (+0%)
Mutual labels:  json-server
react-native-ecommerce
E-commerce mobile application developed using React Native 👔 🎩
Stars: ✭ 60 (+361.54%)
Mutual labels:  json-server
next-ifood
Ifood clone made with NextJS ⚛️
Stars: ✭ 68 (+423.08%)
Mutual labels:  json-server
gostack-rocketshoes-react
👞 Sample store built with Redux and Redux-Saga
Stars: ✭ 35 (+169.23%)
Mutual labels:  json-server
vertical-rhythm-reset
A Sass/SCSS library for responsive vertical rhythm grids, modular scale typography, and CSS normalization.
Stars: ✭ 65 (+400%)
Mutual labels:  reset
html5-kitchen-sink
🚰 Sample markup containing all HTML5 elements for jumpstarting/testing css
Stars: ✭ 290 (+2130.77%)
Mutual labels:  reset
httpbun
A simple HTTP server with responses tuned to be useful in testing HTTP clients. Heavily inspired by httpbin, but doesn't intend to be a perfect clone.
Stars: ✭ 14 (+7.69%)
Mutual labels:  json-server
dva-typescript-antd-starter-kit
A admin dashboard application demo based on antd by typescript and dva
Stars: ✭ 61 (+369.23%)
Mutual labels:  json-server
json-server
Create a dummy REST API from a json file with zero coding in seconds
Stars: ✭ 34 (+161.54%)
Mutual labels:  json-server

json-server-reset json-server version cypress version

Reset middleware for json-server

NPM

Build status semantic-release js-standard-style Cypress.io tests renovate-app badge

Install

Requires Node version 8 or above (because of [email protected] peer dependency).

npm install --save json-server-reset

Use

If you are using json-server, add this module as a middleware. For example, imagine our data file to be data.json with the following resources

{
  "todos": []
}

Then load the file and this middleware

json-server data.json --middlewares ./node_modules/json-server-reset

Then you can work with "todos" and reset the datastore (I am using httpie client in this examples)

$ http :3000/todos
[]
$ http POST :3000/todos text="do something"
{
    "id": 1,
    "text": "do something"
}
$ http POST :3000/todos text="do something else"
{
    "id": 2,
    "text": "do something else"
}
$ http :3000/todos
[
    {
        "id": 1,
        "text": "do something"
    },
    {
        "id": 2,
        "text": "do something else"
    }
]

Now reset the database back to the initial empty list of todos. Note := syntax to send the JSON as a list, not as a string.

$ http POST :3000/reset todos:=[]
$ http :3000/todos
[]

Debugging

Run this module with environment variable

DEBUG=json-server-reset

Using in your own server

If you want to use json-server-reset when building your own server that includes json-server, make sure the to initialize it by passing json-server reference and router database reference, and to add body-parser middleware before the reset. This middleware is included with json-server

Then set it to be the middleware before the rest of the json-server middlewares.

const jsonServer = require('json-server')
const reset = require('json-server-reset')
const setApp = require('json-server-reset/src/set-app')
const bodyParser = require('json-server/lib/server/body-parser')

// create json server and its router first
const server = jsonServer.create()
const router = jsonServer.router(db)
// then pass it to json-server-reset
server.use(setApp(server, router.db))
server.use(bodyParser)
server.use(reset)
// the rest of middlewares
server.use(jsonServer.defaults())
server.use(router)

Examples

Small print

Author: Gleb Bahmutov <[email protected]> © 2017

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2017 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].