JSON Server is a zero coding API that you can spin up and configure in less than a minute. Its probably more for front end developers that need a quick API to test but I’ve used it as a mock API when the existing mocks were either broken or too complicated to setup.
An alternative package is Minimal API InstantAPIs.
Setup
Create a local folder, example
C:\data\devops\json-server
Install json-server
1 | cd json-server |
It does pull down over a hundred node_modules
- who knows what vulnerabilities these will bring :D
- Create the database as
db.json
and populate with json data. It supports auto incrementing id’s and UUIDs. It also supports complex objects likeusers
.
Example data below is from one of my many unfinished projects -_-
1 | { |
- If you adding this to an existing project that uses npm you can just add to the
package.json
file under scripts. If you dont have a file and want to run it as a stub for something then just create the file as below. Alternatively you can runnpm init
, enter through all the steps and it will create a file for you where you can add this script.
1 | { |
- Run the server using the shorthand script you just created
1 | npm run api |
- The data will be avalible at restful endpoints
GET
POST
When posting from postman set the header value Content-Type : application/json