
Transport for U.S. (multiple locations)
TransportationNextBus API. NextBus Incorporated (NextBus) provides a Feed of the prediction and configuration information such that developers can create applications for providing passenger information to the public. The XML Feed data is accessed using URLs with parameters specified in the query string. This document provides: The URLs that can be used. Examples of the XML that is returned
📚 Documentation & Examples
Everything you need to integrate with Transport for U.S. (multiple locations)
🚀 Quick Start Examples
// Transport for U.S. (multiple locations) API Example
const response = await fetch('http://www.nextbus.com/xmlFeedDocs/NextBusXMLFeed.pdf', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
NextBus Public API Documentation
The NextBus public API provides access to real-time transit data, allowing developers to retrieve bus and train schedules and predict their arrival times. This API is available in XML format and can be queried using a set of APIs.
API Endpoints
The NextBus public API endpoint is http://webservices.nextbus.com/service/publicXMLFeed
. The different parameters that can be used along with this endpoint are:
Parameter | Description |
---|---|
command |
Specify the type of request to be made. |
a |
Specify the agency that provides the transit data. |
r |
Specify the route on which to report data. |
s |
Specify the stop IDs. |
Accessing the API with JavaScript
To access the NextBus public API using JavaScript, you can use the fetch
method. Here are some examples of how to use this method:
Example 1: List all available commands
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=help')
.then(response => response.text())
.then(data => console.log(data));
Example 2: List all the available agencies
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList')
.then(response => response.text())
.then(data => console.log(data));
Example 3: Get information about a specific route
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=<agency>&r=<route>')
.then(response => response.text())
.then(data => console.log(data));
Example 4: Get a list of all the stops on a specific route
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=<agency>&r=<route>')
.then(response => response.text())
.then(data => console.log(data));
Example 5: Get real-time scheduling information for a specific stop
fetch('http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=<agency>&s=<stop>&r=<route>')
.then(response => response.text())
.then(data => console.log(data));
Conclusion
The NextBus public API is an essential tool for developers interested in building transit applications. With the help of the API, developers can access real-time transit data and build applications that can help commuters plan their trips more efficiently. The API can be accessed through JavaScript, making it easy to integrate into your web applications.
📊 30-Day Uptime History
Daily uptime tracking showing online vs offline minutes