A developer-friendly Go API for NYC MTA subway real-time data
The MTA API returns all of their data in GTFS format, making it difficult to work with as a developer. This wrapper API simplifies the MTA real-time data by providing clean, developer-friendly endpoints that separate the 36 subway lines and present data in an easy-to-consume JSON format.
config/constants.go and is currently set to 20 minutes.
# Clone the repository
git clone https://github.com/conniexu444/mta-wrapper.git
cd mta-wrapper
# Download dependencies
go mod tidy
# Run the server
go run main.go
The server will start on http://localhost:8080
You can modify the arrival time window by editing config/constants.go:
const ArrivalWindowMinutes = 20 // Change this value as needed
Returns the entire GTFS feed data in JSON format for a specific subway line.
| Parameter | Type | Required | Description |
|---|---|---|---|
route |
string | Yes | Subway line identifier (e.g., A, B, C, 1, 2, 3, L, etc.) |
GET /feed?route=BReturns upcoming train arrivals with various filtering options.
| Parameter | Type | Required | Description |
|---|---|---|---|
route |
string | Yes | Subway line (e.g., L, A, 1) or "ALL" for all lines |
station |
string | No | Station name (kebab-case, e.g., bedford-av, times-sq-42-st) |
direction |
string | No | Travel direction: "N" (Northbound) or "S" (Southbound) |
GET /arrivals?route=LGET /arrivals?route=L&station=bedford-avGET /arrivals?route=ALL&station=times-sq-42-stGET /arrivals?route=L&station=bedford-av&direction=NGET /arrivals?route=ALL&direction=SGET /arrivals?route=A&direction=N# Request with typo:
GET /arrivals?route=L&station=times-sq-42
# Response:
{
"error": "unknown station: times-sq-42",
"did_you_mean": ["times-sq-42-st"]
}
[
{
"Route": "L",
"StopID": "L06N",
"TripID": "123456",
"Time": "2025-10-01T14:32:00Z"
},
{
"Route": "L",
"StopID": "L06N",
"TripID": "123457",
"Time": "2025-10-01T14:45:00Z"
}
]
{
"error": "unknown station: bedfor",
"did_you_mean": [
"bedford-av",
"bedford-park-blvd",
"bedford-park-blvd-lehman-coll"
]
}