DEV Community

Olly
Olly

Posted on

UK postcode lookup, nearest postcodes and distance in one API

If you build anything for UK users, like checkout forms, delivery zones, store finders or "within 10 miles" searches, you need postcode data. UK PostcodeKit wraps the official OS Code-Point Open dataset, covering every postcode in Great Britain, in a fast API.

curl -G "https://uk-postcodekit-postcode-lookup-nearest-distance.p.rapidapi.com/lookup" \
  --data-urlencode "postcode=SW1A 1AA" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: uk-postcodekit-postcode-lookup-nearest-distance.p.rapidapi.com"
Enter fullscreen mode Exit fullscreen mode

You get the latitude and longitude, eastings and northings, and the country, district and ward codes.

Endpoints

  • /validate: checks the format and whether the postcode exists, and normalises it (bs3 1dh becomes BS3 1DH).
  • /autocomplete?q=SW1A 1: suggestions as the user types.
  • /nearest?lat=51.5246&lng=-0.112&radius=200: the postcodes nearest a point.
  • /distance?from=SW1A 1AA&to=EH1 1YZ: straight-line distance, which is 533.79 km here.
  • /outcode?outcode=BS3: the centre point and stats for a district.

For AI agents

It's also an MCP server at https://uk-postcodekit-postcode-lookup-nearest-distance.p.rapidapi.com/mcp.

Contains OS data © Crown copyright and database right. Contains Royal Mail data © Royal Mail copyright and database right. Licensed under OGL v3.0. There's a free plan. UK PostcodeKit on RapidAPI

Top comments (0)