Quickstart: Create and run a mock REST API
mainTo use JSON-Server, follow these steps:
- Create a
db.jsonordb.json5file containing your data. Each top-level key in the JSON object represents a resource. - Start the server using
npx json-server <filename>.
By default, the server starts at http://localhost:3000.
{
"posts": [
{ "id": "1", "title": "a title", "views": 100 },
{ "id": "2", "title": "another title", "views": 200 }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postId": "1" }
],
"profile": {
"name": "typicode"
}
}npx json-server db.json