Git Product home page Git Product logo

railwayapi's Introduction

IRCTC - RailwayAPI

Requirements

Ensure that you have node.js and PostgreSQL installed in your environment.

Setup Project

  1. Clone the repository:

    git clone https://github.com/SomilJain0112/RailwayAPI
  2. Navigate to the project directory:

    cd TEST_DB_REPO-MAIN
  3. Install dependencies:

    npm install
  4. Create a .env file in the project root directory.

  5. 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
  6. You are now ready to use the API.

API Endpoints

User Authentication

[POST] "/user/signup"

Register a new user.

[POST] "/user/login"

Login with existing credentials.

Response Example:

{
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTI1MjM4MDB9.mNhjMKGoar4LENDHnov5sj7lHbHfucn4fPn2047olfA"
}

Train Operations

[POST] "/train/registerTrain"

Register a new train (include headers[x-api-key] = API_KEY).

[GET] "/train/getSeatAvailability"

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

[POST] "/booking/bookSeat"

Book seats on a train (include Bearer {token}).

[GET] "/booking/getBookingDetails/:bookingId"

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

[POST] "/station/registerStations"

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"
  }
}

railwayapi's People

Contributors

somiljain0112 avatar

Watchers

 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.