|
@ -1,28 +1,21 @@ |
|
|
const data = [ |
|
|
|
|
|
{ id: 1, name: 'Conifer', maxHeight: 115 }, |
|
|
|
|
|
{ id: 2, name: 'Eucalyptus', maxHeight: 210 }, |
|
|
|
|
|
{ id: 3, name: 'Ash', maxHeight: 40 }, |
|
|
|
|
|
{ id: 4, name: 'Elder', maxHeight: 5 }, |
|
|
|
|
|
{ id: 5, name: 'Holly', maxHeight: 10 } |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
const data = require('./trees') |
|
|
|
|
|
|
|
|
module.exports = [ |
|
|
module.exports = [ |
|
|
/* CREATE */ |
|
|
/* CREATE */ |
|
|
{ |
|
|
{ |
|
|
request: { method: 'POST' }, |
|
|
request: { method: 'POST' }, |
|
|
response: { |
|
|
|
|
|
status: 201, |
|
|
|
|
|
location: '/tree/1' |
|
|
|
|
|
|
|
|
response: function (ctx) { |
|
|
|
|
|
data.push(ctx.request.body) |
|
|
|
|
|
this.status = 201 |
|
|
|
|
|
this.location = '/tree/1' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
/* READ */ |
|
|
/* READ */ |
|
|
{ |
|
|
{ |
|
|
request: { method: 'GET' }, |
|
|
request: { method: 'GET' }, |
|
|
response: { |
|
|
|
|
|
status: 200, |
|
|
|
|
|
body: function (ctx) { |
|
|
|
|
|
return data.filter(tree => tree.maxHeight > Number(ctx.query.tallerThan)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
response: function (ctx) { |
|
|
|
|
|
this.status = 200 |
|
|
|
|
|
this.body = data.filter(tree => tree.maxHeight > Number(ctx.query.tallerThan || 0)) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
/* UPDATE (forbidden on collection)*/ |
|
|
/* UPDATE (forbidden on collection)*/ |
|
@ -36,3 +29,6 @@ module.exports = [ |
|
|
response: { status: 404 } |
|
|
response: { status: 404 } |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
// curl -i http://localhost:8000/trees -H 'content-type: application/json' -d '{"id":6, "name":"Oak", "maxHeight": 100 }'
|
|
|
|
|
|
// curl -i http://localhost:8000/trees
|