Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ideal-postcodes/core-browser

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ideal-postcodes/core-browser

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

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-60.82%
Maintainers
1
Weekly downloads
 
Created
Source

Ideal Postcodes Javascript Client

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

CircleCI codecov Dependency Status npm version npm bundle size

@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

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 client.lookupPostcode({ postcode: "SW1A2AA" });
Catch Errors
const { IdpcRequestFailedError } = Client.errors;

try {
  await client.lookupAddress({ 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 client.lookupPostcode({ postcode });

Method options

Search for an Address

Return addresses associated with a given query

const query = "10 downing street sw1a";

const addresses = await client.lookupAddress({ 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 client.lookupUdprn({ udprn });

Method options

Test

npm test

Licence

MIT

Keywords

FAQs

Package last updated on 06 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc