4.0.0 • Published 4 months ago

canada-api v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

canada-api

NPM Version License: MIT

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.0.0

4 months ago

3.0.4

1 year ago

3.0.3

2 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago