Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ideal-postcodes/core-browser

ideal-postcodes9.2kMIT3.0.1TypeScript support: included

Browser javascript client for api.ideal-postcodes.co.uk

API, UK, Address, Postcode, Search, Ideal Postcodes, Browser

readme

Ideal Postcodes Javascript Client

JavaScript (browser) client for api.ideal-postcodes.co.uk

CI Cross Browser Testing codecov Dependency Status

npm version npm bundle size Release

@ideal-postcodes/core-browser is the JavaScript browser 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.

Tested against a suite of modern and legacy, mobile and desktop browsers.

@ideal-postcodes/core-browsershould be consumed by a bundler or transpiler (e.g. webpack, parcel, rollup) for minification, module resolution and specific browser support.

core-browser-bundled provides pre-bundled versions of core-browser, which can be immediately dropped into a page.

Example Setup

Webpack Status

Parcel Status

Rollup Status

Polymer Status

Other JavaScript Clients

Documentation

Configuration & Usage

Install

npm install @ideal-postcodes/core-browser

Instantiate

import { Client } from "@ideal-postcodes/core-browser";

const client = new Client({ api_key: "iddqd" });

Configuration options

Use

const addresses = await lookupPostcode({ client: client, postcode: "SW1A2AA" });

Catch Errors

import { errors } from "@ideal-postcodes/core-browser";
const { IdpcRequestFailedError } = errors;

try {
  await lookupAddress({ client, query: "10 downing street" });
} catch (error) {
  if (error instanceof IdpcRequestFailedError) {
    // IdpcRequestFailedError indicates a 402 response code
    // Possibly the key balance has been depleted
  }
}

HTTP Agent and legacy browser support

core-browser uses the Fetch API under the hood to facilitate HTTP requests.

A configuration object can be passed to the Client constructor as a second argument to override certain attributes on the Request of all subsequent fetch requests. Request configuration is documented here.

If you need to support older browsers, please include a fetch polyfill and transpile this library down to ES3. Alternatively use one of our pre-transpiled outputs at ideal-postcodes/core-browser-bundled.


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 lookupPostcode({ client, postcode });

Method options

Search for an Address

Return addresses associated with a given query

const query = "10 downing street sw1a";

const addresses = await lookupAddress({ client, query });

Method options

Search for an Address by UDPRN

Return address for a given udprn

Invalid UDPRN will return null

const udprn = 23747771;

const address = await lookupUdprn({ client, udprn });

Method options

Test

npm test

Licence

MIT

changelog

3.0.1 (2022-04-04)

Bug Fixes

  • Core-Interface: Update to 3.1.0 (045c77e)

3.0.0 (2022-02-14)

Features

  • Core-Interface: Update to 3.0 (a4dc98e)

BREAKING CHANGES

  • Core-Interface: Updates core-interface to 3.0.0

3.0.0-beta.1 (2022-02-03)

Features

  • Core-Interface: Update to 3.0 (478b563)

BREAKING CHANGES

  • Core-Interface: Updates core-interface to 3.0.0

2.0.3 (2021-07-23)

Bug Fixes

  • Tsconfig: Fix target to ES2020 (c42cfe7)

2.0.2 (2021-07-23)

Bug Fixes

  • Core Interface: Bump to 2.0.3 (0a3aa80)

2.0.1 (2021-07-19)

Bug Fixes

  • Deps: Bump core-interface (d1d0bf2)

2.0.0 (2021-06-08)

Features

  • Core Interface: Upgrade to v2 (a7f958f)

BREAKING CHANGES

  • Core Interface: - Package now exports a defaults object
  • Client.defaults has been removed
  • All client config is now stored in client.config
  • All resources have been removed from the client. Instead retrieve these from the library and inject the client. E.g. client.postcodes.retrieve becomes postcodes.retrieve(client, ...)
  • Helper methods (like lookupPostcode, ping) have been removed from the client. Instead retrieve these from teh library and inject the client. E.g. client.lookupPostcode becomes lookupPostcode(client, ...)

1.5.2 (2020-11-27)

Bug Fixes

  • tsconfig: Bump tsconfig (d512e56)

1.5.1 (2020-11-27)

Bug Fixes

  • Core Interface: Bump version (48dcb89)

1.5.0 (2020-10-26)

Features

  • Core Interface: Bump to 1.8.0 (4c8c243)

1.4.0 (2020-10-21)

Features

1.3.0 (2020-08-07)

Features

  • Core Interface: Bump to 1.6.0 (a1dc4b3)

1.2.1 (2020-02-20)

Performance Improvements

  • Request: Drop use of Request (3a328f6)

1.2.0 (2020-02-07)

Features

  • core-interface: Update to 1.5.0 (803d5c1)

1.1.0 (2019-12-06)

Bug Fixes

Features

  • Core-Interface: Update core-interface to 1.4.0 (075f5c9)

1.0.2 (2019-10-22)

Bug Fixes

  • async: Remove async keywords (e0327a7)

1.0.1 (2019-10-21)

Bug Fixes

  • Async: Simplify transpilation by removing async/await (6bf6aa0)

1.0.1 (2019-10-21)

Bug Fixes

  • Async: Simplify transpilation by removing async/await (6bf6aa0)

1.0.0 (2019-10-16)

Features