Skip to main content

https://data.blog.gov.uk/2010/07/29/legislation-gov-uk-api/

legislation.gov.uk API

Posted by: , Posted on: - Categories: Uncategorized

This week The National Archives launched www.legislation.gov.uk, which brings together legislation from across the UK in one place. The site contains legislation as it is originally enacted or made with the revised versions of Acts of Parliament, showing changes to legislation over time.

On the surface the website enables lawyers and ordinary citizens alike to scrutinise the laws on which their legal rights and responsibilities are based. Beneath the surface, legislation.gov.uk is much more just than a website - it is a step change in transparency, providing full access to the statute book as open data. It shows how the web of documents and the web of data can be combined.

The statute book is large and it changes every day. www.legislation.gov.uk provides an API to give developers full and open access to the underlying data, free for re-use under data.gov.uk licence terms. As well as the website, the API is now live and fully operational, with new legislation and new revisions added every day.

RESTful API

Underneath the hood of the legislation.gov.uk is a native XML database and a RESTful API which supports content negotiation. This is the first use of full content negotiation on a large scale government website, to open up access to all the underlying data.

For the web architecturally minded, there are three types of URI for legislation on legislation.gov.uk. These are identifier URIs, document URIs and representation URIs. Identifier URIs are of the form http://www.legislation.gov.uk/id/{type}/{year}/{number} and are used to denote the abstract concept of a piece of legislation - the notion of how it was, how it is and how it will be. These identifier URIs are designed to support the use of legislation as part of the web of Linked Data. Document URIs are for the document. Representation URIs are for the different types of possible rendition of the document, so htm, pdf or xml.

The developer documentation has more details. There is detailed information about the different types of URI, HTTP Responses, Formats
and Searches.

Easy access to data

The simplest way to get hold of the underlying data on legislation.gov.uk is to go to a piece of legislation on the website, either a whole item, or a part or section, and just append /data.xml or /data.rdf to the URL. So, the data for say, Section 1 of the Communications Act 2003 which is at
http://www.legislation.gov.uk/ukpga/2003/21/section/1 is available at http://www.legislation.gov.uk/ukpga/2003/21/section/1/data.xml.

If you have a list, either in browse or search results, similarly you can append /data.feed to return that list in ATOM. The list of Acts in 2003 from http://www.legislation.gov.uk/ukpga/2003 can be returned in ATOM from http://www.legislation.gov.uk/ukpga/2003/data.feed. This also works with search results.

Representing legislation using any kind of data structure is hard. Sean McGrath, who is writing an excellent series of blog posts about his work on the Kansas Legislative Information Services System (starting with http://seanmcgrath.blogspot.com/2010/05/kliss-first-things-first-what-is.html), goes into some detail explaining why. Rather than burden developers with writing XSLTs, as well as providing the underlying XML, we have also made available HTML snippets from the API, for easy inclusion in other websites. The HTML snippets can be retrieved from the full API at legislation.data.gov.uk. For Section 1 above, the HTML snippet is at: http://legislation.data.gov.uk/ukpga/2003/21/section/1/data.htm

What we hope others might do

There are lots of ways to use an API for legislation. The most obvious thing to do is to build a website (which is what we did – the API helping us to create some nice timeline visualisations, which are satisfyingly just HTML and CSS based, but look great). We hope others will do the same, or at least be able to more easily incorporate legislation into their own services.

We envisage bloggers using the API to pull through most recent versions of parts of statutes - perhaps we may see the development of specialist legislation aware plug-ins using tools like WordPress, that automatically mark-up and link legislative references in other documents. Perhaps someone will mash-up current legislation with proposed changes in Bills. Just being able to point at a specific part of a particular statute is very useful.

We are delighted to see that the folk at ESD Toolkit have already linked their listing of the powers and duties in legislation on Local Authorities to legislation.gov.uk URIs and are making use of the API to deliver their service.

We think there is huge potential over the next few years in the development of "accountable systems". These are systems which are explicitly aware of statutory and other legal requirements and are able to process information explicitly in a way that complies with the (ever changing) law. Here the legislation URIs could help enormously, either for people seeking to develop such accountable systems or any time someone wants to integrate an external system with the official source for statutory information. Simply linking definitions in a vocabulary or ontology to the definition in legislation (using say skos:definition in Linked Data) has enormous utility. The identifier URIs enable that to happen.

Parts of the statute book are surprisingly well structured. For example, every year there is one or more Appropriation Acts. These typically contain a schedule with a table listing each government department, the amount allocate to it by Parliament for the year and what that departments’ objectives are. It wouldn't take much to create an XSLT just for these tables in the Appropriation Acts, from the XML provided from the API, to extract this data from all the Appropriation Acts. There are many other examples of almost structured data in legislation, waiting to be feed by developers, now they have easy access to the underlying source.

Of course, the most interesting things people will do with the legislation.gov.uk API will be all the things we haven't thought of. We hope users of the API will share their applications back here on data.gov.uk and tell us how we can continue to improve access to this vital and rich source of public data.

Sharing and comments

Share this page

6 comments

  1. Comment by pigsonthewing posted on

    • Replies to pigsonthewing>

      Comment by Anonymous posted on

      See note from John Sheridan on the discussion page.

  2. Comment by seanr76 posted on

    What discussions page?

  3. Comment by Kate posted on

    Is there a SPARQL endpoint for the legislation data set?

  4. Comment by Anonymous posted on

    How do I get search results back in xml?  If I search using the UI and append /data.feed to the search nothing changes.

  5. Comment by Anam Ahmed posted on

    Do you have any kind of example codes or documentation that we can follow? I am currently trying to add some elements in my 365websitehosting.com web site as per our client request who works in law firm or run a law firm.