Client for api.ofcom.org.uk (Broadband/Mobile speeds by house/postcode)
Client for api.ofcom.org.uk which provides Broadband speeds and Mobile coverage for each address of a specified postcode.
Create an Ofcom API account at the sign up page, and then request access to the products you wish to use:
Name | Description |
---|---|
Broadband Coverage (Basic) | Subscribers can retrieve broadband coverage data against postcodes up to run 100 calls/minute for 50,000 requests per month. |
Broadband Coverage (Premium) | Subscribers can retrieve broadband coverage data against postcodes up to run 500 calls/minute for 150,000 requests per month. |
Mobile Coverage (Basic) | Subscribers can retrieve mobile coverage data against postcodes up to run 100 calls/minute for 50,000 requests per month. |
Mobile Coverage (Premium) | Subscribers can retrieve broadband coverage data against postcodes up to run 500 calls/minute for 150,000 requests per month. |
Add this as a dependency for your TypeScript/JavaScript project, create a .env
file with Ofcom API credentials, and then add client code to your project.
Use your chosen package manager to install this dependency:
npm install --save @stevegoossens/ofcom
yarn add @stevegoossens/ofcom
bun add @stevegoossens/ofcom
The API keys are listed on your profile page as "Primary key" and "Secondary key" for each of the Ofcom API products that you have been granted access.
Create a .env
file containing the credentials, e.g.
BROADBAND_API_KEY=abcdef1234567890
MOBILE_API_KEY=01543987abcdef
import { BroadbandApi } from "@stevegoossens/ofcom";
const broadbandApi = new BroadbandApi();
const postCode = 'BR1 2WJ';
const { data, error, response } = await broadbandApi.coverageByPostCode(postCode);
import { MobileApi } from "@stevegoossens/ofcom";
const mobileApi = new MobileApi();
const postCode = 'BR1 2WJ';
const { data, error, response } = await mobileApi.coverageByPostCode(postCode);
data
: successful response bodyerror
: error response bodyresponse
: the fetch
Response
The Ofcom APIs for Broadband and Mobile are available at:
These can be downloaded (by clicking the "API definition" dropdown, then clicking "Open API 3 (YAML)") and copied to ./data
There are some inaccuracies in the OpenAPI spec files for each API. These need to be corrected in the YAML before generating code from them.
The OpenAPI document for Broadband API has the following errata:
GET /coverage/{PostCode}
Count
property (type: integer)UPRN
property in BroadbandProvision
has format int32
, but this is too small and should be int64
statusCode
(type: integer)message
(type: string)WWW-Authenticate
: AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
ErrorMessage
property is actually named Error
ErrorMessage
property is actually named Error
The OpenAPI document for Mobile API has the following errata:
GET /coverage/{PostCode}
MobileAvailabilityArray
when it is actually MobileAvailability
DBName
property (type: string)UPRN
property in MobileProvision
has format int32
, but this is too small and should be int64
statusCode
(type: integer)message
(type: string)WWW-Authenticate
: AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
ErrorMessage
property is actually named Error
ErrorMessage
property is actually named Error
bun install
Clean out the previously generated code at ./src/openapi-fetch
:
bun clean
Generate the API code:
bun generate:broadband
bun generate:mobile
Apply code style
bun run format
Fix linting errors
bun run lint
Fix linting errors and apply code style
bun run check
Run unit tests
bun test
Tests with coverage
bun test --coverage
bun run build
Publish package to NPM
npm login
Open the generated URL in a browser, login, supply the MFA/2FA code.
First time, if the package does not exist:
npm publish --access=public
The table of contents in this readme was generated by markdown-toc. If you add/remove headings or change the order of them, regenerate the table of contents:
bun toc