Ensure that you have node.js and PostgreSQL installed in your environment.
-
Clone the repository:
git clone https://github.com/SomilJain0112/RailwayAPI
-
Navigate to the project directory:
cd TEST_DB_REPO-MAIN
-
Install dependencies:
npm install
-
Create a
.env
file in the project root directory. -
Add the following environment variables to the
.env
file:DB_NAME=your_database_name DB_PASS=your_database_password DB_HOST=your_database_host API_KEY=your_api_key
-
You are now ready to use the API.
Register a new user.
Login with existing credentials.
Response Example:
{
"message": "Login successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTI1MjM4MDB9.mNhjMKGoar4LENDHnov5sj7lHbHfucn4fPn2047olfA"
}
Train Operations
Register a new train (include headers[x-api-key] = API_KEY).
Get seat availability information (include Bearer {token}).
Response Example:
{
"trains": [
{
"train_id": 1,
"source": "Station C",
"destination": "Station D",
"totalSeats": 100,
"availableSeats": 100,
"distance": 50,
"createdAt": "2024-04-07T22:09:10.599Z",
"updatedAt": "2024-04-07T22:09:10.599Z",
"sourceStationId": 3,
"destinationStationId": 4
}
]
}
Booking Operations
Book seats on a train (include Bearer {token}).
Get booking details by ID (include Bearer {token}).
Response Example:
{
"booking": {
"booking_id": 1,
"seatsBooked": 2,
"train_id": 1,
"user_id": 1,
"createdAt": "2024-04-07T23:21:22.630Z",
"updatedAt": "2024-04-07T23:21:22.630Z"
}
}
Station Operations
Register new stations (include headers[x-api-key] = API_KEY).
Response Example:
{
"message": "Train registered successfully",
"train": {
"availableSeats": 100,
"train_id": 1,
"source": "Station C",
"destination": "Station D",
"totalSeats": 100,
"distance": 50,
"sourceStationId": 3,
"destinationStationId": 4,
"updatedAt": "2024-04-07T22:09:10.599Z",
"createdAt": "2024-04-07T22:09:10.599Z"
}
}