DC Metro API – Show Real-Time Train Arrivals with Javascript

I’ve worked with Twitter, Instagram and Facebook APIs. Those are always a bundle of unpredictable joy/not, as APIs usually are. The WMATA (DC Metro) API is fairly easy to work with by comparison. They don’t have to worry about anyone’s personally identifiable information (PII), hence, less headaches for developers. They provide an adequate level of documentation and are reasonably responsive over email. All issues I had while working with this code were easy enough to resolve, using the ol’ Googley machine and common sense. A business lead I worked with was extra enthusiastic about the project, so he did email the API developers a few times and they responded on the same day.

The rate limit is 10 calls/second and 50,000 calls per day, which should work just fine for most uses. I’d pay extra attention here if you have multiple versions of the code during development (using the live end point) or, if you have a live version out and are working on changes, while using the live API (which is sometimes unavoidable, since there’s no dev end point).

In general, if you call it 3 times a minute or every 20 seconds, as the WMATA’s own real time arrivals web app does, you’ll be more than ok. Here’s a screenshot:

You can see their list of real time arrival stations here. It works rather well and uses their Real-Time Rail Predictions API, but one thing I’d certainly do differently – it’s literally reloading the whole page every 20 seconds to update the data. I’m guessing a backend developer put this together real quick, while working under several deadlines. A simple AJAX call can fix this (there are multitudes of examples of this on StackOverflow alone).

Note: if their app/API feed is down, their real time arrivals link just shows a mostly blank page:

Again, I’m guessing this was done in a hurry.