JSON Server - fake REST API. - Site will work locally ONLY!!!

How to work with JSON Server to get a full fake REST API
  1. In your current project run npm i -D json-server
  2. Create db.json at the root folder of the project
  3. Write in the db.json file. Attention: this is a json file.
    {
    "users": [
    { "id": "23", "firstName": "Bill", "age": 20 },
    { "id": "40", "firstName": "Alex", "age": 42 }
    ]
    }
    
  4. Add in package.json of the project
    "scripts": {
    "json-server": "json-server --watch db.json --port 5000",
    }
    
  5. This will run in a different process
  6. Run in a separate terminal: npm run json-server
  7. Read messages an the terminal
  8. Run in the browser: http://localhost:3000/users
  9. Run in the browser: http://localhost:3000/users/23
  10. See project 222 for example and GraphQL Stephen Grider course, lecture 13 - A Realistic Data Source
  11. See more at https://www.npmjs.com/package/json-server
  12. For React:
    • Add in package.json
        "proxy": "http://localhost:5000"
      
    • Usage
        const url = '/comments';
      
        try {
          const { data } = await axios.get(url);
        } ...