canada-api v4.0.0
canada-api
Cross platform API for fetching public data from canada.ca.
Browser
<script src="https://cdn.jsdelivr.net/npm/canada-api@4.0.0"></script>
Node 10+
Install
npm install canada-api
Usage
const ca = require('canada-api')
Core API
ca.request(url)
url
{string|URL} relative or absolute URL on canada.ca- Returns: {Promise} Fulfills with axios response {Object} upon success
Throws {Error} if the request does not complete successfully or if the destination URL is not on canada.ca.
{
"data": {},
"status": 200,
"statusText": "OK",
"headers": {},
"config": {},
"request": {}
}
ca.normalize(url)
url
{string|URL} node URL
Validates and formats canada.ca. Throws an {Error} if the URL is invalid, or the type requested is not possible.
Basic API
ca.children(url)
url
{string|URL} absolute or relative URL- Returns: {Promise} Fulfills with {Object} containing child nodes
Parses sitemaps to get a list of child nodes.
{
"data": [
{
"path": "https://www.canada.ca/en/department-national-defence/...",
"lastmod": "2022-09-20"
},
]
}
Getting children of DAM folders/assets is not available.
ca.content(url)
url
{string|URL} absolute or relative URL- Returns: {Promise} Fulfills with {Object} containing document contents
Retrieves the document contents.
{
"data": "<!DOCTYPE html>\r\n...."
}
ca.meta(url)
url
{string|URL} absolute or relative URL- Returns: {Promise} Fulfills with {Object} containing metadata properties
Nodes contain a variety of metadata properties that can be accessed through a public API. Some properties such as date formats are reformatted for consistency.
{
"data": {
"cq:lastModified": "2022-10-25T19:16:28.000Z",
"fluidWidth": false,
}
}
4 months ago
1 year ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago