A RESTful JSON API for the NextBus XML Feed

Published on by Morgan Ney

NextBus Inc. has been providing real-time passenger information about transit agencies through their public XML feed for years. The data provided has always been top notch, especially for building real-time web applications, but in my opinion the service has three glaring shortcomings:

  • It ignores useful HTTP status codes. Every response is an HTTP 200 (even errors).
  • It's focused around commands and query parameters to act on resources instead of being RESTful.
  • The application/json media type is not supported.

While working at NextBus I helped them develop a new API that addresses these shortcomings. However, since leaving last October I noticed they still haven't made it public and I've found myself frustrated at having to deal with the old, crusty XML feed to access real-time, public transit data. To that end, I decided to create restbus, a Node.js proxy server that acts as a RESTful JSON API for the NextBus XML feed. This way I can more easily create applications around public transit data using front end JavaScript MV* frameworks like Backbone.js or AngularJS.

After installing with npm install restbus, you can start the restbus server in a couple different ways:

Now your application can access the NextBus XML feed via a RESTful JSON API running at http://localhost:3535. Check out a full demo to see some of the sample responses.

Relevant to  REST, JSON, API, Node.js
Get in Touch

BizzyBtyes is owned by Morgan Ney, a father, husband, and web developer originally from the San Francisco Bay Area and now living in Coarsegold, Ca. just south of Yosemite.