Giter Site home page Giter Site logo

parthipan-natkunam / fuber Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 126 KB

A POC prototype code to simulate the RESTful APIs of an imaginary cab booking service

JavaScript 93.57% HTML 6.43%
node-js restful-api poc server-side-rendering jade-template-engine express-js

fuber's Introduction

fuber

A POC prototype code to simulate the RESTful APIs of an imaginary cab booking service

screenshot

End of Ride Console Log:

console log

Important Note:

To successfully run the project, it is advised to use node version 8.11.2 or greater

steps to run the project:

  1. Install the dependencies for the node server code
    cd fuber/server
    npm install

  2. 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

  3. To start the server
    npm start

The testing and API interactions were done through postman with raw JSON type in the request body.

Approach taken:

  1. The distance is calculated by using Pythogoras theorem to simplify for the purpose of POC.

distance calc

  1. The entire operation is modelled as a service.
  2. Restful APIs consume the service to provide required response on request.
  3. Request validators have been put in place using JOI module for POST requests.
  4. For maintaing a simplistic POC approach, all data are held in memory.

Tech Stack:

  1. Node.js
  2. Express
  3. Jade (for server-side rendering of markup template)
  4. Postman (for API Testing)

API

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

Request, Response Sample:

bookCab:

request:
{
	"id": 1,
	"loc":{
		"lat": 4,
		"long": 3.6	
	},
	"dropLoc":{
		"lat": 6,
		"long": 7.6	
	},
	"prefCol": "any"	
}
Response:
{
    "id": 3,
    "cabId": 5,
    "cabIndex": 4,
    "userLoc": [
        4,
        3.6
    ],
    "dropLoc": [
        6,
        7.6
    ]
}

beginWait

Request:
{
	"id": 3
}
Response:
{
    "success": "Waiting time started"
}

beginRide

Request:
{
	"id": 3
}
Response
{
    "success": "ride has begun"
}

endRide

Request:
{
	"id":4
}
Response:
{
    "total": 8.94,
    "travelCost": 8.94,
    "waitingCost": 0,
    "pinkFactor": 0
}

The root (/) API call to fetch all availble Cabs

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.

Assumptions made:

  1. The cab cannot be cancelled once it has started waiting for the client or the ride is started.
  2. Can be cancelled before any of the above happens.
  3. All the distance unit is assumed to be in Km by default.

fuber's People

Contributors

parthipan-natkunam avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.