faa-notam-sdk

The FAA Notam API

Usage no npm install needed!

<script type="module">
  import faaNotamSdk from 'https://cdn.skypack.dev/faa-notam-sdk';
</script>

README

FAA Notam API SDK

SDK for the FAA Notam API. This library acts as a wrapper around the Notam API.

Run lint

Run lint with the following commands:

npm install
npm lint

To fix possible lint errors run

npm lint:fix

How to use this sdk

  1. Install the sdk

    $ npm install faa-notam-sdk
    
  2. Create an instance of this wrapper

    
    const { NotamApiSdk } = require('faa-notam-sdk')
    
    const sdkInstance = new NotamApiSdk('localhost:8080/api/v1', 'secretapikey')
    
    • the first argument is the API base url. E.g. 'http://localhost:8080/api/v1'
    • the second argument is the api key. E.g. 'secretapikey'
  3. Use the wrapper methods

Every function in this wrapper will return a promise. Call the functions with the query parameters passed as a json object (this is optional). Passing invalid query params, a wrong api key or invalid base url will throw an error. The error response is the raw error thrown from the API. Handle errors using ordinary javascript async/await or promise syntax.

There are 3 available methods, getGeoJson(queryParams), which returns JSON data, getAidap(queryParams), which returns XML data, and getAixm(queryParams), which returns XML data. The optional param queryParams is the query parameters as a JSON object to be passed to the respective API endpoint.

All URIs are relative to the base url parameter passed to NotamApiSdk.

Method HTTP request Description
getGeoJson GET /notams/geoJson Get geoJson data. Returns json.
getAidap GET /notams/aidap Get aidap data. Returns xml.
getAixm GET /notams/aixm Get aixm data. Returns xml.

Response format

Each method will return a Promise that will resolve to an object with the following syntax {"pageSize": 0,"pageNum": 0,"totalCount": 0,"totalPages": 0,"items":[]}. The items array will contain either JSON objects in the case of getGeoJson, or strings with raw XML data in the case of getAidap or getAixm.

Example usage

You can replace getGeoJson in the below example with getAidap or getAixm (note that queryParams is optional). If queryParams contains parameters that are not accepted, an error will be thrown.

const { NotamApiSdk } = require('faa-notam-sdk')

const sdkInstance = new NotamApiSdk('localhost:8080/api/v1', 'secretapikey')

const queryParams = {
  notamNumber: 'somestring',
  pageNum: 10,
  sortOrder: 'Asc'
}

// async/await syntax
try {
  const res = await sdkInstance.getGeoJson(queryParams)
  // do something with the response

} catch (err) {
  // do something with the error

}

// promise syntax
sdkInstance.getGeoJson(queryParams)
  .then(res => {
    // do something with the response

  })
  .catch(err => {
    // do something with the error

  })

How to publish this package

  • If you do not already have an npm user account, you can create an account:
    $ npm adduser
    
  • Or you can login with your account:
    $ npm login
    
  • Publish the package to npm
    $ npm publish
    
    NOTE: if the package name is not available than you will have to use a different name. Change the name field in the file package.json. If you change the name of the package, then wherever you see faa-notam-sdk above you must use your new name instead.