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.
Create a local folder, example
It does pull down over a hundred
node_modules - who knows what vulnerabilities these will bring :D
- Create the database as
db.jsonand populate with json data. It supports auto incrementing id’s and UUIDs. It also supports complex objects like
Example data below is from one of my many unfinished projects -_-
- If you adding this to an existing project that uses npm you can just add to the
package.jsonfile 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 run
npm init, enter through all the steps and it will create a file for you where you can add this script.
- Run the server using the shorthand script you just created
npm run api
- The data will be avalible at restful endpoints
When posting from postman set the header value
Content-Type : application/json