Skip to content

RESTful API about locomotives using Django REST framework

License

Notifications You must be signed in to change notification settings

cyberpsychofc/LocomotiveDataAPI

Repository files navigation

LocomotiveDataAPI

LocomotiveDataAPI is a RESTful Web Service made in Django REST framework which aims to provide information Indian locomotives (Indian Railways) scraped from Wikipedia using Beautiful Soup.

Run Locally

Clone the project

  git clone https://github.com/cyberpsychofc/LocomotiveDataAPI

Go to the project directory

Install dependencies

  pip install beautifulsoup4
  pip install requests
  pip install Django
  pip install djangorestframework
  pip install pyjwt
  pip install django-cors-headers

Start the server

  python manage.py runserver

Updating the Database

Update the database before making an API call.

  python manage.py updatemodels

How to consume the API

Via Postman

Register a User

Create a superuser via CI.

  python manage.py createsuperuser

Register your standard users using Postman

  POST /api/register

Pass the following parameters

Parameter Type Description
name string ${name}
email string ${email}
password string ${passwrd}

Logging in

  POST /api/login

Pass the following parameters

Parameter Type Description
email string ${email}
password string ${passwrd}

Status

To check if you're logged in

  GET /api/user

If you're logged in you will see your user details in the response

Logout

  POST /api/logout

IMPORTANT

Provide the generated JWT token at the time of login in the Authorization tab in Postman token

Demo

Endpoint demonstration of the API. For more information refer to the documentaiton.

https://localhost:8000/locomotives

demo

Lets search for a particular locomotive e.g. WAP-1

https://localhost:8000/locomotives/wap-1

demo2

API Reference

Get list of all locomotives

  GET /api/locomotives/
Parameter Type Description
locomotives string Required. Returns entire list of locomotives

Get a particular locomotive

  GET /api/locomotives/${name}
Parameter Type Description
name string Required. Returns the details of a particular locomotive

Get a list of Electric locomotives

  GET /api/locomotives/electric
Parameter Type Description
electric string Required. Returns entire list of electric locomotives

Get a list of Diesel locomotives

  GET /api/locomotives/diesel
Parameter Type Description
diesel string Required. Returns entire list of diesel locomotives

Get a list of Broad-Gauge locomotives

  GET /api/locomotives/broad
Parameter Type Description
broad string Required. Returns entire list of broad-gauge locomotives

Get a list of Meter-Gauge locomotives

  GET /api/locomotives/meter
Parameter Type Description
meter string Required. Returns entire list of meter-gauge locomotives

Get a list of Narrow-Gauge locomotives

  GET /api/locomotives/narrow
Parameter Type Description
narrow string Required. Returns entire list of narrow-gauge locomotives

Get a list of Narrower-Gauge locomotives

  GET /api/locomotives/narrower
Parameter Type Description
narrower string Required. Returns entire list of narrower-gauge locomotives

Authors