This is a demo of json-server.
Live demo: https://demo-json-server.herokuapp.com/
db.json
contains the data.
There are two branches.
- master: is a basic setup that can be deployed to Heroku.
- add_auth: requires users to pass in the api secret in order to access the api.
- I'm using dotenv to keep track of
API_SECRET
- normally I would gitignore
.env
, but I didn't to that in this demo so you can see how to usedotenv
to authorized the api
- I'm using dotenv to keep track of
install packages
$ npm install
start the api
$ npm run start
- see entire database
- see all users
http://localhost:3001/api/users
- see user with id of 1
http://localhost:3001/api/users/1
- see all teams
http://localhost:3001/api/teams
- see all users that belong to a team with id 2
http://localhost:3001/api/teams/2/users
- see user with id 1 and their team
http://localhost:3001/api/users/1?_expand=team
- add new user.
send POST request + json containing user info to:
http://localhost:3001/api/users
- update existing user.
sent PUT request + json containing updated fields to:
http://localhost:3001/api/users/1
- delete existing user
sent DELETE request to:
http://localhost:3001/api/users/1
$ git checkout add_auth
- see all users
http://localhost:3001/api/users?secret=password123
- see user with id 1 and their team
http://localhost:3001/api/users/1?_expand=team&secret=password123