Git Product home page Git Product logo

demo-json-server's Introduction

Demo of json-server

This is a demo of json-server.

Live demo: https://demo-json-server.herokuapp.com/

Notes

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 use dotenv to authorized the api

Setup

install packages

$ npm install

start the api

$ npm run start

Usage

  1. see entire database

http://localhost:3001/api/db

  1. see all users

http://localhost:3001/api/users

  1. see user with id of 1

http://localhost:3001/api/users/1

  1. see all teams

http://localhost:3001/api/teams

  1. see all users that belong to a team with id 2

http://localhost:3001/api/teams/2/users

  1. see user with id 1 and their team

http://localhost:3001/api/users/1?_expand=team

  1. add new user.

send POST request + json containing user info to:

http://localhost:3001/api/users

  1. update existing user.

sent PUT request + json containing updated fields to:

http://localhost:3001/api/users/1

  1. delete existing user

sent DELETE request to:

http://localhost:3001/api/users/1

Add authentication to api

$ git checkout add_auth
  1. see all users

http://localhost:3001/api/users?secret=password123

  1. see user with id 1 and their team

http://localhost:3001/api/users/1?_expand=team&secret=password123

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.