Data.parliament.uk
GovernmentAccessing UK Parliament Data with the Parliament API
If you're looking for data on the UK Parliament, the Parliament API is the perfect solution. It offers a wide range of data - from information on Members of Parliament to details about House of Commons business.
To get started with the Parliament API, simply head to http://www.data.parliament.uk/developers/ and sign up for an API key. Once you have your key, you can start making requests to the API and receiving data in return.
Using JavaScript to Access the Parliament API
To make requests to the Parliament API using JavaScript, you'll need to use a library like axios
or fetch
. Here are some example code snippets to help you get started:
Get information about a specific Member of Parliament
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get(`http://api.data.parliament.uk/members/${memberId}.json`, {
params: {
apikey: API_KEY,
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Get a list of all written answers to parliamentary questions
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get('http://api.data.parliament.uk/writtens/search.json', {
params: {
apikey: API_KEY,
}
})
.then(response => {
console.log(response.data.items);
})
.catch(error => {
console.error(error);
});
Get the latest business in the House of Commons
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get('http://api.data.parliament.uk/calendar.json', {
params: {
apikey: API_KEY,
house: 'commons',
},
})
.then(response => {
const latestBusiness = response.data[0];
console.log(latestBusiness.title);
})
.catch(error => {
console.error(error);
});
Conclusion
The Parliament API is an incredibly useful resource for anyone looking to work with data on the UK Parliament. With a little bit of JavaScript, you can easily make requests to the API and receive data in return. Try it out for yourself and start building amazing applications powered by parliamentary data.