A POC prototype code to simulate the RESTful APIs of an imaginary cab booking service
To successfully run the project, it is advised to use node version 8.11.2
or greater
-
Install the dependencies for the node server code
cd fuber/server
npm install
-
To run the unit test
npm test
The tests cases in the module assumes that all cabs are available at the start of the app. So it is advised to run this command first before running the app, if you are to run tests.
** Note: ** The API test Json file from Postman is in a folder within the tests folder -
To start the server
npm start
The testing and API interactions were done through postman with raw JSON type in the request body.
- The distance is calculated by using Pythogoras theorem to simplify for the purpose of POC.
- The entire operation is modelled as a service.
- Restful APIs consume the service to provide required response on request.
- Request validators have been put in place using
JOI
module forPOST
requests. - For maintaing a simplistic POC approach, all data are held in memory.
- Node.js
- Express
- Jade (for server-side rendering of markup template)
- Postman (for API Testing)
Endpoint | type | request params | response |
---|---|---|---|
/ | get | - | a list of available cab data |
/bookCab | post | id(userId),location,dropLocation,preferedColor | a ride object containing ride details or error |
/cancelCab | post | id(rideId) | success or error property |
/beginWait | post | id(rideId) | success or error property |
/beginRide | post | id(rideId) | success or error property |
/endRide | post | id(rideId) | total cost data for the ride or error |
{
"id": 1,
"loc":{
"lat": 4,
"long": 3.6
},
"dropLoc":{
"lat": 6,
"long": 7.6
},
"prefCol": "any"
}
{
"id": 3,
"cabId": 5,
"cabIndex": 4,
"userLoc": [
4,
3.6
],
"dropLoc": [
6,
7.6
]
}
{
"id": 3
}
{
"success": "Waiting time started"
}
{
"id": 3
}
{
"success": "ride has begun"
}
{
"id":4
}
{
"total": 8.94,
"travelCost": 8.94,
"waitingCost": 0,
"pinkFactor": 0
}
This is a GET
type request
The response for this request will be a server-side rendered HTML template showing available cabs with highlights for pink cabs.
- The cab cannot be cancelled once it has started waiting for the client or the ride is started.
- Can be cancelled before any of the above happens.
- All the distance unit is assumed to be in Km by default.