During some of the trainings we deliver, we need some operational mock ReSTful API with CRUD operations support and filtering features.
Generate JSON data
JSON Generator is an original online tool that allows us to generate a bunch of resources using a specific but yet intuitive syntax.
You can now download or copy the generate JSON array.
Setup the server
First, let’s create a NodeJS module!
yarn init # or npm init
JSON Server is an easy to setup ReSTful API mock server that uses a JSON file as a database for storing resources.
- Let’s install it.
yarn add json-server # or npm install --save json-server
2. Now, we can add the JSON array generated before to a
db.json file with the following structure:
3. Finally, we just have to add the
start script in the
"start": "json-server db.json"
The API should be running now and you can start querying it locally but you might want to deploy it somewhere in the cloud so you can share it with your friends or use it from Stackblitz or any other online code editor.
Deploy using Zeit’s Now
The good news is that thanks to Zeit’s Now, deploying the mock API will just require us to type one command:
Well, first you will have to sign up on Zeit (https://zeit.co/signup) and install
now CLI using
yarn global add now (or
npm install -g now).
Now, we can go back to our API’s NodeJS module we created before and run the