Node.js module for using the DC Master Address Repository API.
npm install dc-mar
const client = require('dc-mar').createClient();
client.findLocation('1600 Penn')
.then(function (addresses) {
const address = addresses[0];
console.log([
address.fullAddress(),
address.smd(),
address.latitude(),
address.longitude(),
]);
});
/*
[ '1600 PENNSYLVANIA AVENUE NW',
'2A01',
38.89766766,
-77.03654468 ]
*/
This is the main class you'll want to use. If you're creating only one, you may want to use the
createClient
function.
const client = new Client(options);
The optional options
argument is an object with the following properties, which
you probably won't want to change from the defaults unless you have unusual needs:
-
request
: a function that accepts a URL or an options object containingurl
andparams
(URL parameters) and returns a promise that resolves to an object derived from the JSON in the body of the HTTP response. It defaults to the function exported byrequest-promise-native
with athen
added to extract thedata
property from the response. The function should throw on HTTP errors. -
baseUrl
: a string to be used as the base URL for the Master Address Repository API. It defaults tohttps://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/
. -
minInterval
: an integer setting the minimum interval between API requests in milliseconds. It defaults to 3000, which is the interval DC OCTO asks users to adhere to. Use a lower value only if you're doing testing in which you're mocking the HTTP requests so that you're not actually hitting the server.
A utility method used by the methods for
the various API operations.
The operation
argument is a string, the name of the API operation.
The parameters
argument is an object, the parameters to be passed to the operation
endpoint.
You won't need this method unless you want to call a method that doesn't (yet) have its
own method defined. The operations called are always the REST versions, which end in
2
(meaning that 2
is appended to the operation name if it's not already there).
The request
method returns a promise returned by the request
function as defined
in the options from the constructor.
When given a string representing an address in Washington, DC, returns a promise that resolves
to an array of Address
objects corresponding to that string. If the optional raw
argument is
true, the promise instead resolves to the entire object derived from the JSON response, which
may be useful for debugging.
When given an array of strings representing addresses in Washington, DC, returns a promise
that resolves to an array of arrays of Address
objects corresponding to those strings, in order.
Like findLocation
, it has an optional raw
argument.
When given latitude and longitude as floats, returns a promise that resolves to an array of
Address
objects representing the addresses nearest to those coordinates.
Like findLocation
, it has an optional raw
argument.
A factory function for creating Client
objects, so that you can do
const client = require('dc-mar').createClient();
instead of
const Client = require('dc-mar').Client;
const client = new Client();
This is the class of the objects returned by findLocation
and findLocationBatch
. You probably
won't need to use the constructor directly, but it is exported in case it's needed
(for instanceof
tests, for example). When JSON.stringify() is called on an Address object, it
returns a JSON representation of the properties
object (which is what was used to create the
Address originally).
const address = new Address(properties);
The properties
argument (required) is an object containing the properties described in the
MAR data dictionary,
plus a ConfidenceLevel
property.
An object containing the properties provided in the constructor.
These values should mostly be accessed through other methods like .ward()
or through .get()
if no specific method exists.
Method to get the advisory neighborhood commission, or ANC (string).
Method to get the confidence level of the search result (integer).
Available only for addresses returned by findLocation
or findLocationBatch
.
Method to get the distance from the provided coordinates (float).
Available only for addresses returned by reverseLatLngGeocoding
.
Method to get the fullAddress (string).
Method to get the value of a property. The propertyName
argument is a string. The return value is
a string or number, depending on the property, or null.
Method to get the image URL (string).
Method to get the latitude (float).
Method to get the longitude (float).
Method to get the police district (integer);
Method to get the voting precinct (integer).
Method to get the police service area (integer);
Method to get the quadrant (string).
Method to get the single member district within the ANC (string).
Method to get the ward (integer).
Method to get the ZIP code (string).