User Tools

Site Tools


informatica:linux:json-server
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


informatica:linux:json-server [2020/02/25 20:51] (current) – created jose
Line 1: Line 1:
 +====== json-server ======
 +https://github.com/typicode/json-server
 +
 +Create a db.json file with some data
 +
 +<code>
 + 
 +{
 +  "posts": [
 +    { "id": 1, "title": "json-server", "author": "typicode" }
 +  ],
 +  "comments": [
 +    { "id": 1, "body": "some comment", "postId": 1 }
 +  ],
 +  "profile": { "name": "typicode" }
 +}
 +</code>
 +
 +
 +json-server --watch db.json
 +
 +Tenemos 3 categorías, posts, comments y profile.
 +
 +Para ver posts:
 +
 +curl http://localhost:3000/posts
 +<code>
 +[
 +  {
 +    "id": 1,
 +    "title": "json-server",
 +    "author": "typicode"
 +  }
 +]
 +</code>
 +
 +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