User Tools

Site Tools


informatica:linux:json-server

json-server

https://github.com/typicode/json-server

Create a db.json file with some data

 
{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

json-server –watch db.json

Tenemos 3 categorías, posts, comments y profile.

Para ver posts:

curl http://localhost:3000/posts

[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  }
]

Si queremos añadir uno: curl -H “Content-Type: application/json” -d '{“title”: “hola que tal”,“author”:“adios”}' -X POST http://localhost:3000/posts

informatica/linux/json-server.txt · Last modified: 2020/02/25 20:51 by jose