You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
831 B

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. const data = require('./trees')
  2. module.exports = [
  3. /* CREATE */
  4. {
  5. request: { method: 'POST' },
  6. response: function (ctx) {
  7. data.push(ctx.request.body)
  8. this.status = 201
  9. this.location = '/tree/1'
  10. }
  11. },
  12. /* READ */
  13. {
  14. request: { method: 'GET' },
  15. response: function (ctx) {
  16. this.status = 200
  17. this.body = data.filter(tree => tree.maxHeight > Number(ctx.query.tallerThan || 0))
  18. }
  19. },
  20. /* UPDATE (forbidden on collection)*/
  21. {
  22. request: { method: 'PUT' },
  23. response: { status: 404 }
  24. },
  25. /* DELETE (forbidden on collection) */
  26. {
  27. request: { method: 'DELETE' },
  28. response: { status: 404 }
  29. }
  30. ]
  31. // curl -i http://localhost:8000/trees -H 'content-type: application/json' -d '{"id":6, "name":"Oak", "maxHeight": 100 }'
  32. // curl -i http://localhost:8000/trees