A REST API to get current public transit options between 2 locations in New Jersey. The API supports using latitude
and longitude
for source location. The API in-turn relies upon services such as NJ TRANSIT to get the transit information.
Follow these steps to setup the application
git clone https://github.com/vamshikr/tran_jersey.git && \
cd tran_jersey
Register with https://datasource.njtransit.com/SignUp.aspx to get access credentials.
NJT_USERNAME=<your njtransit username>
NJT_PASSWORD=<your njtransit password>
NJT_BASE_URL=http://njttraindata_tst.njtransit.com:8090/njttraindata.asmx
GOOGLE_MAPS_APIKEY=<your google maps api key>
This application is containerized using Docker. To build and run the dockerized application, run the following command:
./docker_run.sh
or
docker-compose up --build
If all the above steps pass, then the tran_jersey
application is ready to use. The REST API is now accessible on localhost:8080
.
[2019-12-21 13:09:27 +0000] [6] [INFO] Starting gunicorn 20.0.4
[2019-12-21 13:09:27 +0000] [6] [INFO] Listening at: http://0.0.0.0:8080 (6)
[2019-12-21 13:09:27 +0000] [6] [INFO] Using worker: aiohttp.GunicornUVLoopWebWorker
[2019-12-21 13:09:27 +0000] [8] [INFO] Booting worker with pid: 8
21-12-2019:13:09:28,31 INFO [app.py:54] Google Maps service available
-
The API endpoint is
/transit/schedule
and the URL is http://localhost:8080/transit/schedule -
The API only support the
GET
method
Key | Value | Description |
---|---|---|
|
Name of the city in New Jersey |
Example: "Aberdeen-Matawan", Optional if using |
|
Name of the city in New Jersey |
Example: "Hazlet", This parameter is required |
|
floating-point number between |
Optional and if used, should be along with |
|
floating-point number between |
Optional and if used, along with |
|
a positive number |
Example: |
By default the API only returns the first 3
chronologically sorted results, use page
parameters to access the subsequent results
curl -X GET --insecure --globoff 'http://localhost:8080/transit/schedule?origin=Aberdeen-Matawan&destination=Hazlet'
{
"schedule": [
{
"origin": "Aberdeen-Matawan",
"departure_time": "21-Dec-2019 02:11:15 PM",
"train_line": "North Jersey Coast Line",
"track_number": "1",
"destination": "Hazlet",
"arrival_time": "21-Dec-2019 02:15:00 PM"
},
{
"origin": "Aberdeen-Matawan",
"departure_time": "21-Dec-2019 03:07:30 PM",
"train_line": "North Jersey Coast Line",
"track_number": "1",
"destination": "Hazlet",
"arrival_time": "21-Dec-2019 03:10:30 PM"
},
{
"origin": "Aberdeen-Matawan",
"departure_time": "21-Dec-2019 04:11:15 PM",
"train_line": "North Jersey Coast Line",
"track_number": "1",
"destination": "Hazlet",
"arrival_time": "21-Dec-2019 04:14:15 PM"
}
]
}
Key | Value |
---|---|
|
A list of transit options |
|
Origin station |
|
Departure time |
|
Train name/line |
|
Track number |
|
Destination station |
|
Destination arrival time |
|
result page number |
curl --globoff -X GET 'http://localhost:8080/transit/schedule?origin=Aberdeen-Matawan&destination=Hazlet&page=2'
curl --globoff -X GET 'http://localhost:8080/transit/schedule?latitude=40.713472&longitude=-74.185678&destination=Hazlet&page=2
curl --globoff -X GET 'https://www.vamboy.co/transit/schedule?latitude=40.301149&longitude=-73.991174&destination=New%20York%20Penn%20Station'