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 body -
error
: error response body -
response
: thefetch
Response
The Ofcom APIs for Broadband and Mobile are available at:
- https://api.ofcom.org.uk/api-details#api=ofcom-connected-nations-broadband-api
- https://api.ofcom.org.uk/api-details#api=ofcom-connected-nations-api
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}
- 200 response body schema
- is missing the
Count
property (type: integer)
- is missing the
- 401 response is missing
- body schema has:
-
statusCode
(type: integer) -
message
(type: string)
-
- headers:
-
WWW-Authenticate
:AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
-
- body schema has:
- 404 response body schema
-
ErrorMessage
property is actually namedError
-
- 500 response body schema
-
ErrorMessage
property is actually namedError
-
- 200 response body schema
The OpenAPI document for Mobile API has the following errata:
-
GET /coverage/{PostCode}
- 200 response body schema
- is specified as
MobileAvailabilityArray
when it is actuallyMobileAvailability
- is missing the
DBName
property (type: string)
- is specified as
- 401 response is missing
- body schema has:
-
statusCode
(type: integer) -
message
(type: string)
-
- headers:
-
WWW-Authenticate
:AzureApiManagementKey realm="https://api-proxy.ofcom.org.uk/broadband",name="Ocp-Apim-Subscription-Key",type="header"
-
- body schema has:
- 404 response body schema
-
ErrorMessage
property is actually namedError
-
- 500 response body schema
-
ErrorMessage
property is actually namedError
-
- 200 response body schema
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