BCLaws
GovernmentAn Introduction to bclaws.ca Public API
If you are looking to access legal information in British Columbia, Canada, you might find the public API provided by bclaws.ca useful. The API exposes a set of endpoints which returns metadata and documents related to legal publications made available on bclaws.ca. The documents can be in XML or HTML format.
Here, we will cover the steps required to get started using the bclaws.ca public API in JavaScript, along with example code to help illustrate how the API can be used.
Getting Access
To use the public API, you will need an API key. You can register for an API key at the following link - https://api.bclaws.ca/register/. Once you have obtained your API key, you can use it to authenticate requests.
Making API Requests
To make requests to the API endpoints, you can use any HTTP request library that supports GET and POST requests, but for now, we will make use of XMLHttpRequest
. In the following example, we are requesting the metadata for the British Columbia Court of Appeal:
var xhr = new XMLHttpRequest();
var apiEndpoint = 'https://api.bclaws.ca/v1/councils/court_of_appeal/metadata?key=YOUR_API_KEY';
xhr.open('GET', apiEndpoint, true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
console.log(data);
}
};
xhr.send();
Examples
Get Metadata for Legal Publications
To retrieve metadata for a specific legal publication, you can make a GET request to the following endpoint:
https://api.bclaws.ca/v1/{publication_type}/{publication_id}/metadata?key=YOUR_API_KEY
Here's an example of getting metadata for the "Mental Health Act" publication:
var xhr = new XMLHttpRequest();
var apiEndpoint = 'https://api.bclaws.ca/v1/statutes_and_regulations/mental_health_act/metadata?key=YOUR_API_KEY';
xhr.open('GET', apiEndpoint, true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
console.log(data);
}
};
xhr.send();
Retrieve Legal Document in HTML format
To retrieve a specific legal publication in HTML format, you can make a GET request to the following endpoint:
https://api.bclaws.ca/v1/{publication_type}/{publication_id}?key=YOUR_API_KEY&fmt=html
Here's an example of retrieving "Mental Health Act" in HTML format:
var xhr = new XMLHttpRequest();
var apiEndpoint = 'https://api.bclaws.ca/v1/statutes_and_regulations/mental_health_act?key=YOUR_API_KEY&fmt=html';
xhr.open('GET', apiEndpoint, true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = xhr.responseText;
console.log(data);
}
};
xhr.send();
Retrieve Legal Document in XML format
To retrieve a specific legal publication in XML format, you can make a GET request to the following endpoint:
https://api.bclaws.ca/v1/{publication_type}/{publication_id}?key=YOUR_API_KEY
Here's an example of retrieving "Mental Health Act" in XML format:
var xhr = new XMLHttpRequest();
var apiEndpoint = 'https://api.bclaws.ca/v1/statutes_and_regulations/mental_health_act?key=YOUR_API_KEY';
xhr.open('GET', apiEndpoint, true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var data = xhr.responseText;
console.log(data);
}
};
xhr.send();
Conclusion
The bclaws.ca public API provides easy access to British Columbia legal publications in XML and HTML formats. Using the API, we can fetch metadata and legal documents from various publications. In this article, we demonstrated how to use the API from JavaScript using XMLHttpRequest
.