- Task
XRides, delivers about 200 rides per minute or 288,000 rides per day.
Now,they want to send this data to your system via an API. Your task is to create this
API and save the data into PostgreSQL.The API should be designed, keeping in mind the real-time streaming nature of data and the
burst of requests at peak times of the day. The user of this API expects an acknowledgment,
that the data is accepted and a way to track if the request fails.
- Pre-Requisites
Node.js
Express.js
PostgreSQL
JavaScript, HTML
- Implemenation of the REST API rides
Inserts the data provided by the user in the Data Base
-
URL
/rides:
-
Method:
POST
-
Data Params
Required:
bookingId=[integer]
userId=[integer]
vehicleId=[integer]
packageId=[integer]
travelTypeId=[integer]
travelId=[integer]
mobileId=[integer]
desktopId=[integer]
fromAreaId=[integer]
toAreaId=[integer]
fromId=[integer]
destId=[integer]
begDate=[integer]
endDate=[DATE]
fromLat=[TEXT]
fromLong=[TEXT]
toLat=[TEXT]
toLong=[TEXT]
-
Success Response:
- Code: 200
Content:{message: "Your Requested has been accepted" }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ message : "Could not process the request, Try again" }
- Code: 404 NOT FOUND
-
Handling a large number of Requests
- Load Balancing --> We will use the concept of Load Balancing for handling a large number of request
-
Sample Call
route.post("/", (req, res, next) => { Ride.addRide( // Sending request with desired parameters ) .then(() => { // Render accepted }) .catch((err) => { // Render failed }) })
-
Setting Up
- Download the essential node modules
npm install
Download and setup PostgreSQL
PostgreSQL
Start the Server
npm start server.js