2015-11-19 20:40:41 +00:00
|
|
|
const data = require('./trees')
|
2015-11-19 16:03:01 +00:00
|
|
|
|
2015-11-18 16:37:16 +00:00
|
|
|
module.exports = [
|
2015-11-19 16:03:01 +00:00
|
|
|
/* CREATE */
|
2015-11-18 16:37:16 +00:00
|
|
|
{
|
2015-11-19 16:03:01 +00:00
|
|
|
request: { method: 'POST' },
|
2015-11-19 20:40:41 +00:00
|
|
|
response: function (ctx) {
|
|
|
|
data.push(ctx.request.body)
|
|
|
|
this.status = 201
|
|
|
|
this.location = '/tree/1'
|
2015-11-18 16:37:16 +00:00
|
|
|
}
|
|
|
|
},
|
2015-11-19 16:03:01 +00:00
|
|
|
/* READ */
|
2015-11-18 16:37:16 +00:00
|
|
|
{
|
2015-11-19 16:03:01 +00:00
|
|
|
request: { method: 'GET' },
|
2015-11-19 20:40:41 +00:00
|
|
|
response: function (ctx) {
|
|
|
|
this.status = 200
|
|
|
|
this.body = data.filter(tree => tree.maxHeight > Number(ctx.query.tallerThan || 0))
|
2015-11-18 16:37:16 +00:00
|
|
|
}
|
2015-11-19 16:03:01 +00:00
|
|
|
},
|
|
|
|
/* UPDATE (forbidden on collection)*/
|
|
|
|
{
|
|
|
|
request: { method: 'PUT' },
|
|
|
|
response: { status: 404 }
|
|
|
|
},
|
|
|
|
/* DELETE (forbidden on collection) */
|
|
|
|
{
|
|
|
|
request: { method: 'DELETE' },
|
|
|
|
response: { status: 404 }
|
2015-11-18 16:37:16 +00:00
|
|
|
}
|
|
|
|
]
|
2015-11-19 20:40:41 +00:00
|
|
|
|
|
|
|
// curl -i http://localhost:8000/trees -H 'content-type: application/json' -d '{"id":6, "name":"Oak", "maxHeight": 100 }'
|
|
|
|
// curl -i http://localhost:8000/trees
|