Rest API for Cab booking in Spring boot, JPA, MYSQL, Postman

Online Cab Booking is a backend project. In this project, we have used Spring boot to create RestApi for the cab booking system. It provides APIs to handle the cab booking operation, user management, and Cab and driver management APIs.

Let’s understand more about the tools, technologies, features, and functionality of this cab booking API.

Used tools and technologies

  • It uses Spring boot to create RestAPIS.
  • JPA repository to manage the database transactions.
  • MYSQL is a database to store information.
  • It uses JSON to transfer the data over the APIs.
  • Postman to execute the API.
  • The backend is running over the Tomcat Server.

Abstract of cab booking

The main object of the online cab booking system project is to book cabs for customers. there will be some other users as well like admin and driver that can operate the application and perform their roles and responsibilities.

Admin can manage the customers or users, cabs, cab bookings, driver details, and payment details. at the same time driver can manage their cabs and customers.

let’s check the RestApis with the payload that we created for online cab booking. 

RestApis of cab booking in spring boot

Following are the created APIs according to the user roles.

Common APIs
  • Post request for User/Driver Registration
  • Login and generate an auth token
After login as an Admin User
  • Get request to find the list of users.
  • Post request to add the users.
  • Update request to update any user.
  • Delete request to delete any user by id.
  • Post request to add the brands.
  • Get request to find the list of the brands.
  • Update request to update any brand.
  • Delete request to brand any user by id.
  • Post request to add the Cabs.
  • Get request to find the list of the Cabs.
  • Update request to update any Cab.
  • Delete request to Cab any user by id.
  • Get request to check the list of booked cabs.
  • Get request to check the booked cab by a user.
After login by the User
  • Create a Get request to display the user’s own information.
  • Post request to book a cab.
  • Get request to find the booking history by the user.
After login by Driver
  • Get request to view the bookings that coming from users.

It uses JWT  and Spring security authentication, to access the API. So before accessing any API, you have to log in and generate the auth token as a key.

API Validations

  • Duplication of user names should not allow.
  • Apis should now allow adding duplicate cabs.
  • Get User by id should not allow 0 input.
  • In case the record is not available API should return the “Record not found” exception.

API payload to Book a cab

{
    "driverid": 8,
    "cabid": 1,
    "userid": 7,
    "drivername": "Driver",
    "bookingdate": "2022-10-16",
    "totalprice": 52000,
    "status": "Booked"

}

Leave a Comment

Your email address will not be published. Required fields are marked *