$ brew install node
$ npm install -g json-server
jsonデータ
{
"movies": [
{"id": 1, "name": "The Godfather", "director":"Francis Ford Coppola", "rating": 9.1},
{"id": 2, "name": "Casablanca", "director": "Michael Curtiz", "rating": 8.8}
]
}
$ json-server --watch db.json
http://localhost:3000/moviesをみる 結果
[
{
"id": 1,
"name": "The Godfather",
"director": "Francis Ford Coppola",
"rating": 9.1
},
{
"id": 2,
"name": "Casablanca",
"director": "Michael Curtiz",
"rating": 8.8
}
]
$ curl -X POST -H "Content-Type: application/json" -d '{
"id": 3,
"name": "Inception",
"director": "Christopher Nolan",
"rating": 9.0
}' "http://localhost:3000/movies"
$ curl -X GET "http://localhost:3000/movies/3"
結果
{
"id": 3,
"name": "Inception",
"director": "Christopher Nolan",
"rating": 9
}
リンク