These address API examples show how to verify a UK postcode against Royal Mail PAF in JavaScript, Python, PHP, Ruby and cURL. Each is a single GET request with your API key in the Authorization header, returning matching addresses from ~31M UK delivery points across ~1.8M postcodes as JSON.
What does a lookup request look like in each language?
Pick your stack — the request shape is identical, only the HTTP client changes:
const res = await fetch(
"https://api.autopostcode.com/v1/lookup?postcode=SW1A1AA",
{ headers: { Authorization: "Bearer " + process.env.AUTOPOSTCODE_KEY } }
);
const { addresses } = await res.json();Authorization header attached.What does the JSON response contain?
A successful lookup returns an addresses array, each with line fields, town, postcode and a UPRN, so you can store a stable identifier alongside the formatted address.
| Field | Example | Use |
|---|---|---|
| line1 | 10 Downing Street | Primary address line |
| town | London | Post town |
| postcode | SW1A 2AA | Formatted postcode |
| uprn | 100023336956 | Stable unique reference |
New to the API? Start with the API quickstart, then explore the full REST API reference and the postcode lookup API endpoints.
A modern, UK-first alternative
AutoPostcode uses the same Royal Mail PAF data as Loqate, Fetchify and Ideal Postcodes, with clean REST examples and an affordable per-lookup price.
Frequently asked questions
Where can I find address API code examples?
This page is a gallery of copy-paste address API examples in JavaScript, Python, PHP, Ruby and cURL. Each snippet calls the AutoPostcode endpoint with a Bearer key and returns Royal Mail PAF addresses as JSON.
What does an address lookup API request look like?
A lookup is a single GET request: send the postcode as a query parameter with your API key in the Authorization header, and you receive a JSON array of matching PAF addresses. Every example on this page follows that same shape.
Which languages have postcode API code snippets here?
JavaScript (fetch), Python (requests), PHP (cURL), Ruby (Net::HTTP) and a raw cURL command. The API is plain REST, so any HTTP client works the same way.
Do I call the address API from the browser or the server?
Call it from your server so the API key stays secret. The browser should hit your own endpoint, which proxies to AutoPostcode with the key attached.
Is the returned data Royal Mail PAF?
Yes. Every example returns addresses from Royal Mail PAF, covering ~31M UK delivery points across ~1.8M postcodes, so results are authoritative.
How do I handle errors and rate limits in these examples?
Check the HTTP status: 401 means a bad key, 429 means you hit the rate limit, and 200 returns addresses. Back off on 429 and surface a friendly message on 4xx.
Ready to get started?
Add Royal Mail PAF-verified UK address lookup to your site in minutes — start free, no card required.
