This is the official implementation of the First Street Foundation API in JavaScript.
For more in-depth guides, usage and API access, please see the documentation at docs.firststreet.dev.
First install firststreet-js:
npm install firststreet-js
Next, import it into your project
import FirstStreet from 'firststreet-js';
// Or commonjs
const FirstStreet = require('firststreet-js');
In order to use the First Street Foundation API, you must register for an API key at https://firststreet.dev.
// Create a new First Street Foundation API Client
const fs = new FirstStreet("api-key");
The client supports querying Firststreet API endpoints corresponding to documentation, extensive examples can be found in ./tests
directory.
Generally, for endpoints that require location and fsid, first need to initialize lookup object as in below example, and then use it for querying the data:
const fs = new FirstStreet(apiKey);
const lookup = fs.lookup('city', { fsid: 4808860 });
const probability = await lookup.probability('count');
For endpoints that do not use fsid, please pass the parameter(s) directly to the endpoint call, as in this example:
const fs = new FirstStreet(apiKey);
const historic = await fs.historic('event', { id: 12 });
Similarly, if endpoint accepts other parameters in addition to location lookup, then these can be passed to the endpoint call directly:
const fs = new FirstStreet(apiKey);
const lookup = fs.lookup('property', { fsid: 4801470191 });
const aal = await lookup.economic('aal', { basement: true, floorElevation: 122, depth: 100 });
Errors from the API and network errors are propagated to caller.