Warning:
This wiki has been archived and is now read-only.
Api example
From Data on the Web Best Practices
Contents
DWBP API Documentation
API URL
http://data.mycity.example.com/transport/api/
List all bus routes
GET /bus/routes
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
| transport-agency | string | optional | If provided, retrieves data only for the given transport agency |
| full-details | boolean | optional | If set to true, all details for each route is returned. Default is false |
Example
http://data.mycity.example.com/transport/api/bus/routes?transport-agency=DTA&full-details=false
Response
{
"results": {"transport-agency": "http://data.mycity.example.com/transport-agency/DTA",
"routes":[
{"id":"1",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/1"},
{"id":"3",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/3"},
{"id":"5",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/5"},
{"id":"8",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/8"},
{"id":"10",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/10"},
{"id":"12a",
"uri": "http://data.mycity.example.com/transport/road/bus/route/id/12a"}
]
}
}
List all bus stops
GET /bus/stops
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
| transport-agency | string | optional | If provided, retrieves data only for the given transport agency |
| route | string | optional | If provided, retrieves data only for the given route |
| full-details | boolean | optional | If set to true, all details for each stop is returned. Default is false |
Example
Response
Three different ways to describe stops: * using simple fields, * using fields defined in http://w3c.github.io/dwbp/dwbp-example.html and * using geojson.
{
"results": {"transport-agency": "http://data.mycity.example.com/transport-agency/DTA",
"route": "http://data.mycity.example.com/transport/road/bus/route/id/5",
"stops":[
{"id":"345",
"uri": "http://data.mycity.example.com/transport/road/bus/stop/id/345",
"name": "Castle Avenue, Sunset Drive",
"description": "Castle Avenue, Sunset Drive",
"latitude": "-3.731862",
"longitude": "-38.526670",
"zone_id": "x20"
},
{"stop_id":"483",
"stop_uri": "http://data.mycity.example.com/transport/road/bus/stop/id/483",
"stop_name": "Main Street, Lily Park",
"stop_desc": "Main Street, Lily Park",
"stop_lat": "-3.731541",
"stop_long": "-38.535157",
"zone_id": "x20"
},
{"id":"541",
"uri": "http://data.mycity.example.com/transport/road/bus/stop/id/541",
"name": "West Avenue, Beech Road",
"desc": "West Avenue, Beech Road",
"location": { "type": "Point",
"coordinates": [-38.514354, -3.734957] },
"zone_id": "x22"
}
]
}
}
Get real-time info for bus stop
GET /bus/realtime/{stopid}
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
| full-details | boolean | optional | If set to true, all details for each stop is returned. Default is false |
| transport-agency | string | optional | If provided, retrieves data only for the given transport agency |
| route | string | optional | If provided, retrieves data only for the given route |
stop - string - mandatory, retrieves real-time information for given stop. full-details - boolean - optional, if set to true, all details for each stop is return. Default is false transport agency - string - optional, if provided retrieves data only for given transport agency. route - string - optional, if provided retrieves data only for given route.
Example
http://data.mycity.example.com/transport/api/bus/realtime/345
Response
{
"results": {"id":"345",
"uri":"http://data.mycity.example.com/transport/road/bus/stop/id/345",
"timestamp":"2016-05-03T13:54:16Z",
"realtime":[
{"transport-agency": "http://data.mycity.example.com/transport-agency/DTA",
"route": "http://data.mycity.example.com/transport/road/bus/route/id/5",
"duetime":"2016-05-03T14:00Z"
},
{"transport-agency": "http://data.mycity.example.com/transport-agency/ABC",
"route": "http://data.mycity.example.com/transport/road/bus/route/id/8",
"duetime":"2016-05-03T14:03Z"
},
{"transport-agency": "http://data.mycity.example.com/transport-agency/ABC",
"route": "http://data.mycity.example.com/transport/road/bus/route/id/12a",
"duetime":"2016-05-03T14:05Z"
},
{"transport-agency": "http://data.mycity.example.com/transport-agency/DTA",
"route": "http://data.mycity.example.com/transport/road/bus/route/id/5",
"duetime":"2016-05-03T14:06Z"
}
]
}
}