项目作者: sandeep33-k

项目描述 :
Sample REST API using nodejs expressjs mongodb
高级语言: JavaScript
项目地址: git://github.com/sandeep33-k/battle-node-api.git
创建时间: 2018-11-21T16:50:32Z
项目社区:https://github.com/sandeep33-k/battle-node-api

开源协议:

下载


sample-solution-route-system-api

Code examples for following post:

Install

  • Install Node.js
  • Install project dependencies with following command

npm i -g azure-functions-core-tools@2 --unsafe-perm true

Run

Run project with following command

func start

Functionalities

There are several functionalities implemented in the stub. See linked posts for more details how to use them.

APIs

Database where you can add or get route details with JSON showing RESTful web services functionality described in blog post.

http://localhost:7071/api/getRoutes

Predefined routes available in this API.

  1. -SAMPLE RESPONSE
  2. {
  3. "statusCode" : 200,
  4. "data" : [
  5. {
  6. "routeId" : 1,
  7. "time" : 10,
  8. "distance" : 10,
  9. "expense" : 4
  10. },
  11. {
  12. "routeId" : 2,
  13. "time" : 8,
  14. "distance" : 14,
  15. "expense" : 8
  16. },
  17. {
  18. "routeId" : 3,
  19. "time" : 12,
  20. "distance" : 12,
  21. "expense" : 6
  22. }
  23. ]
  24. }

http://localhost:7071/api/addRoute

Add new route to the system.Send routeId, time, distance, expense as query parameter

  1. -SAMPLE INPUT REQUEST
  2. http://localhost:7071/api/addRoute?routeId=5&time=12&distance=22&expense=9
  3. -SAMPLE RESPONSE
  4. {
  5. "statusCode" : 200,
  6. "data" : New Route Added Successfully with id = 5
  7. }

http://localhost:7071/api/getProjectedRoute

This is the major API which will give the best available routes based on less money and less time. By defualt the api will give 7 days data or pass ?days=5 as query params and get 5 days projected data. if the user spend more 12 euros for coffee then he has to skip the coffee for rest of the days

  1. -SAMPLE RESPONSE
  2. {
  3. "statusCode" : 200,
  4. "data" : [
  5. {
  6. "day" : Day 1,
  7. "route" : {
  8. "routeID" : 1,
  9. "time" : 10,
  10. "distance" : 10,
  11. "coffeePrice" : 4
  12. }
  13. },
  14. {
  15. "day" : Day 2,
  16. "route" : {
  17. "routeID" : 1,
  18. "time" : 10,
  19. "distance" : 10,
  20. "coffeePrice" : 4
  21. }
  22. },
  23. {
  24. "day" : Day 3,
  25. "route" : {
  26. "routeID" : 1,
  27. "time" : 10,
  28. "distance" : 10,
  29. "coffeePrice" : 4
  30. }
  31. },
  32. {
  33. "day" : Day 4,
  34. "route" : {
  35. "routeID" : 2,
  36. "time" : 8,
  37. "distance" : 14,
  38. "coffeePrice" : Skip Coffee
  39. }
  40. },
  41. {
  42. "day" : Day 5,
  43. "route" : {
  44. "routeID" : 2,
  45. "time" : 8,
  46. "distance" : 14,
  47. "coffeePrice" : Skip Coffee
  48. }
  49. },
  50. {
  51. "day" : Day 6,
  52. "route" : {
  53. "routeID" : 2,
  54. "time" : 8,
  55. "distance" : 14,
  56. "coffeePrice" : Skip Coffee
  57. }
  58. },
  59. {
  60. "day" : Day 7,
  61. "route" : {
  62. "routeID" : 2,
  63. "time" : 8,
  64. "distance" : 14,
  65. "coffeePrice" : Skip Coffee
  66. }
  67. }
  68. ]
  69. }