Putting APIs first: legislation.gov.uk

Mention the word “API” to the wrong audience and blank looks shortly follow. For the uninitiated, an API, or “Application Programming Interface”, is a way for one computer to use information or services held on another computer, often across the internet. The strategists say that developing high quality APIs has the potential to transform public services. One example where this is proving to be the case is legislation.gov.uk, the official UK legislation website, operated by The National Archives.

With legislation.gov.uk we aimed to open-up access to the government’s legislation database, by creating an API first. The legislation.gov.uk API allows anyone to access the data we hold in the database, or to use the services we have built, such as the search or to dynamically create PDF documents from the data. We wanted to show that government could create a high-quality, technically sophisticated API, following the principles of both REST and Linked Data. We also wanted our API to be fully open, with no restrictions on use, and no need to register before using it.

We developed the API and then built the legislation.gov.uk website on top of it. The API isn’t a bolt-on or additional feature, it is the beating heart of the service. Thanks to this approach it is very easy to access legislation data – just add /data.xml or /data.rdf to any web page containing legislation, or /data.feed, to any list or search results. One benefit of this approach is that the website, in a way, also documents the API for developers, helping them understand this complex data. Since launching the API we’ve seen several third party applications be developed, including two different iPhone / iPad apps, as well as innovative new products, such as a service for law lecturers to create and self-publish relevant extracts of legislation for their courses.

Many users assume, when they look at a page of legislation on the web, that it is current, in force and applies to where they live. Unfortunately legislation is a lot more complicated than that (this clip from Yes Minister may be an exaggeration, but you’ll get the idea). One Act may amend others, often in complicated ways. A major challenge with operating legislation.gov.uk is keeping pace with all the changes, so we can provide the current view of legislation the public expects. We have an editorial team at The National Archives, who identify all the changes and update the database. We create new versions of the legislation to show how it has changed over time. The difficulty is we can only manage to apply changes to primary legislation (Acts) and the number of changes to apply has been growing every year. It is a mammoth task and we needed to think how we could bring more expertise to bear on this growing challenge.

The API is enabling us to develop an entirely new approach to updating legislation, inspired by the open source software movement – our Expert Participation Programme. We are inviting people from outside The National Archives to work with us, to apply changes to the legislation in the database. Quality is maintained through our editorial practice and a stringent process of review. It is an exciting time as private sector companies are now investing, employing people to work with us to bring the database up to date and to maintain it. The API gives them ready and easy access to the data, which they can include in their own products and services. To help people use the data we have also published the code we use to present the content in HTML and PDF on github: https://github.com/legislation/legislation.  Importantly, everything remains public, open and free, under the Open Government Licence. It is a win-win situation.

The legislation.gov.uk API has changed everything for us. It powers our website. It has enabled us to move to an open data business model, securing the editorial effort we need from the private sector for this important source of public data. It allows us to deliver information and services across channels and platforms through third party applications. We are developing other tools that use the API, using Linked Data – from recording the provenance of new legislation as it is converted from one format to another, to a suite of web based editorial tools for legislation, including a natural language processing capability that automatically identifies the legislative effects. Everything we do is underpinned by the API and Linked Data. With the foundations in place, the possibilities of what can be done with legislation data are now almost limitless.

About the author: John Sheridan is Head of Legislation Services at The National Archives


  1. For those interested in learning more about legislation.gov.uk and the challenges of legislation as data, here are some additional links:

    – A post on the Legal Informatics blog for Cornell University Legal Information Institute: http://blog.law.cornell.edu/voxpop/2010/08/15/legislationgovuk/ describing the thinking behind legislation.gov.uk.

    – Various postings by Jeni Tennison (Twitter: @jenit), the Technical Architect of legislation.gov.uk: http://www.jenitennison.com/blog/taxonomy/term/37/9 The API is in no small measure Jeni’s work and stands as a testament to her and her colleagues talent.

    – A posting by our contractor (TSO), on their “Open Up” site about the work they have been doing using Natural Language Processing: http://openup.tso.co.uk/blog/toward-automating-complex-legislation-updates

    – Relevant to this general field, but not related to legislation.gov.uk, Rinke Hoekstra writing about the Metalex Document Server: http://blog.law.cornell.edu/voxpop/2011/10/25/the-metalex-document-server/

    – There is generally some great stuff by Sean McGrath about legislation and XML. This gives a flavour: http://seanmcgrath.blogspot.co.uk/2010/06/xml-in-legislatureparliament.html

  2. Terrific and groundbreaking work, as always, John. Would love your ideas on what an API should look like across jurisdictions. What common principles of the API would you urge other countries to adopt?

  3. I’m very glad to hear that the API is being put to such good use.

    Do you have any plans to open-source your NLP efforts so that interested citizens with some legal and technological knowledge (like me!) can observe and possibly help drive that forward also?

  4. I represent the Practical Law Company, one of the private sector organisations involved in the Expert Participation Programme. We’re really excited by these developments and salute John Sheridan and his team for their groundbreaking and elegant work on the API and legislation database. Legislation.gov.uk is the official publishing place for UK legislation and so it is really important work.

    The programme is now starting to make a real and visible difference to the status of legislation on the website. By employing people to work with National Archives and as a first step, we’ve been able to ensure that the Companies Act 2006 is now fully consolidated on legislation.gov.uk. This is a particularly important piece of legislation for many of our customers but we intend to carry on the consolidation work on other legislation.

    Well done, National Archives.

  5. I have finished parsing all of the US State bills into XML, using a schema based on Grant’s SLIM. We’ve just finished implementing a “quick search” function on our website to let people search for free. So that’s all coming along.

    Now I am looking at opening up an API into the data. Reading your post I regret that I didn’t bake the API in from the beginning. None the less, your suggestions and additional links are very helpful. Thank you for sharing!

    Kudos, John. As always, you are an inspiration.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s