postcodes.io client
Abstracts access to the postcodes.io
API.
var PostcodesIO = ;var postcodes = ; postcodes;
Installation
$ npm install postcodesio-client
Usage
Create an instance of the client, providing options if you wish:
var PostcodesIO = ; var postcodes = 'https://api.postcodes.io' headers: 'User-Agent': 'MyAwesomeApp/1.0.0' // default {} - extra headers;
Make requests using Promises:
postcodes ;
Not found (404) responses from the API are not considered errors. Instead, the
output will be null
.
postcodes;
Only Promises (Promises/A+) are supported - callbacks are not. The following two sections specify exactly how you can apply Promises to the reference below.
Promises
postcodes methodparameters... ;
method
- the method you want to callparameters
- any arguments specific to that method (see Methods)error
- instance ofError
outputs
- any outputs for that method (see Methods)
Both parameters
and outputs
can mean zero, one, or many arguments. These are
specified for each method.
Methods
Lookup
Get lots of data for a postcode or outcode.
postcodes
Parameters:
code
- string - the postcode or outcode to retrieve
Outputs:
This may also be called explicitly as postcodes.lookupPostcode(postcode)
or postcodes.lookupOutcode(outcode)
.
Near Coordinate
Find postcodes closest to a coordinate.
postcodes
This may also be called explicitly as postcodes.nearCoordinate(latitude, longitude, options)
.
Parameters:
latitude
- number - the latitude of the coordinatelongitude
- number - the longitude of the coordinateoptions
- object - optional, only available with an explicit call
Outputs:
postcodes
- array of Postcode - the nearby postcodes
Near Postcode
Find the postcodes closest to another postcode.
Warning: results may include the original postcode.
postcodes
This may also be called explicitly as postcodes.nearPostcode(postcode)
.
Parameters:
postcode
- string - the postcode to search around
Outputs:
postcodes
- array of Postcode - the nearby postcodes
Reverse Geocode
Find the single closest postcode to a coordinate.
postcodes
Parameters:
latitude
- number - the latitude of the coordinatelongitude
- number - the longitude of the coordinate
Outputs:
postcode
- Postcode - the nearby postcode
Validate
Validates that the postcode exists. (Means it is in the official Royal Mail Postcode Address File).
postcodes
Parameters:
postcode
- string - the postcode to retrieve
Outputs:
exists
- boolean - indicates existence of postcode
Random
Retrieve a random postcode. Not really sure why you'd want to do this, but here it is...
postcodes
Outputs:
postcode
- Postcode - a random postcode
Types
Postcode
Example:
Outcode
Example:
Testing
Install the development dependencies first:
$ npm install
Then run the tests:
$ npm test
Support
Please open an issue on this repository.
Authors
- James Billingham james@jamesbillingham.com
License
MIT licensed - see LICENSE file