Node.js client for api.ideal-postcodes.co.uk
@ideal-postcodes/core-node
is the Node.js client for api.ideal-postcodes.co.uk
Our JavaScript client implements a common interface defined at @ideal-postcodes/core-interface.
High level client documentation can be found at core-interface.
In depth client documentation can be found at core-interface.ideal-postcodes.dev.
@ideal-postcodes/core-node
is tested against all maintained, stable releases.
Links
- Configuration & Usage
- Quickstart
- Client Documentation
- In Depth Client Documentation
- npm Module
- GitHub Repository
Other JavaScript Clients
Documentation
Configuration & Usage
Install
npm install @ideal-postcodes/core-node
Instantiate
const Client = ; // or, if applicable, const client = api_key: "iddqd" ;
Use
const addresses = await client;
Catch Errors
const IdpcRequestFailedError = Clienterrors; try await client; catch error if error instanceof IdpcRequestFailedError // IdpcRequestFailedError indicates a 402 response code // Possibly the key balance has been depleted
Configure HTTP Agent
core-node
uses got as its underlying HTTP client. The Ideal Postcodes API client can also be optionally configured with a got options object which is fed to got on every request.
Be aware this options object will overwrite any existing got HTTP request parameters.
const client = api_key: "iddqd" cache: // Instantiate a cache: https://github.com/sindresorhus/got#cache-1 hooks: // Hook into HTTP responses: https://github.com/sindresorhus/got#hooksafterresponse { ; ; return response; } ;
Proxy HTTP Requests
You can proxy requests by configuring the underlying got HTTP client.
const tunnel = ; const client = config agent: tunnel;
Quickstart
The client exposes a number of simple methods to get at the most common tasks when interacting with the API. Below is a (incomplete) list of commonly used methods.
For a complete list of client methods, including low level resource methods, please see the core-interface documentation
Lookup a Postcode
Return addresses associated with a given postcode
const postcode = "id11qd"; const addresses = await client;
Search for an Address
Return addresses associated with a given query
const query = "10 downing street sw1a"; const addresses = await client;
Search for an Address by UDPRN
Return address for a given udprn
Invalid UDPRN will return null
const udprn = 23747771; const address = await client;
Test
npm test
Licence
MIT