Skip to content

Instantly share code, notes, and snippets.

@richleach
Created April 21, 2021 23:31
Show Gist options
  • Save richleach/a85c6531b01e1f4922c488693a6df5cf to your computer and use it in GitHub Desktop.
Save richleach/a85c6531b01e1f4922c488693a6df5cf to your computer and use it in GitHub Desktop.
JSON Server handy to use when your backend/API/endpoints aren't available but maybe you know the data/object structure. You have to npm install it, then run it to watch a particular file (endpoint).
//Using JSON Server
//Install JSON Server locally
npm install -g json-server
//Run JSON Server
json-server --watch data/db.json --port 8000
//which means http://localhost:8000/notes will return the 4 JS objects below.
//Create a file like below named "db.json". All of the objects below are part of the "notes" endpoint
{
"notes": [
{
"title": "Sophie's birthday bash",
"details": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
"category": "reminders",
"id": 1
},
{
"title": "Complete my JS training",
"details": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took.",
"category": "work",
"id": 2
},
{
"title": "Order a pizza!",
"details": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.\nLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
"category": "todos",
"id": 3
},
{
"title": "Pay da rent",
"details": "Rent man wants his money",
"category": "money",
"id": 4
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment