Jeremy Walker

Software Developer & Social Entrepreneur

Accessing the National Rail SOAP API

Yesterday a friend asked with some help in accessing the National Rail API - an almost totally undocumented SOAP API, with useless error messages and support staff utterly lacking in knowledge - you may be suspecting that I'm not particularly impressed with it.

After 4hrs of trial and error just trying to access it, I finally got some working code, which I have put on Github and bundled as a Gem. It should be pretty easy to expand/change if you want to do more.

You can find usage instructions on the National Rail API project page. For reference. If you want any help with accessing the SOAP API, pop an issue request on Github, post a comment on here, or drop me an email.

Which just leaves me to ask, why couldn't National Rail have done this themselves?!

Share This Post




Hi Jeremy!

I've just been trying in vain to access the SOAP API through PHP. I saw your post and thought it was about time I learned rails. I've just got a sinatra setup, (very nice isn't it?), I'm a bit lost on how to "bundle" your Gem. Do you have any pointers?

Thanks for reading,



Jeremy Walker

Hi Jon,

So bundler is a way to manage an application's dependancies. You can read more about it at http://gembundler.com/

Firstly, install bundler with:
gem install bundler

Next, cd into your project and create a file called 'Gemfile' with the contents:
source 'https://rubygems.org'
gem 'sinatra'
gem 'json'
gem 'national_rail'

Now install your gems with:
bundle install

That installs the gems onto your system and places details in a Gemfile.lock

You can now run your Sinatra server with something like:
bundle exec ruby -rubygems server.rb

Does that work for you?

Post a Comment

I'd love to hear your thoughts :)