TheCodeGuy.Postcode 1.0.0

dotnet add package TheCodeGuy.Postcode --version 1.0.0
                    
NuGet\Install-Package TheCodeGuy.Postcode -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TheCodeGuy.Postcode" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TheCodeGuy.Postcode" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TheCodeGuy.Postcode" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TheCodeGuy.Postcode --version 1.0.0
                    
#r "nuget: TheCodeGuy.Postcode, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TheCodeGuy.Postcode@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TheCodeGuy.Postcode&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TheCodeGuy.Postcode&version=1.0.0
                    
Install as a Cake Tool

TheCodeGuy.Postcode

A simple .NET client for The Code Guy Postcode API. UK postcode lookup, validation, nearest search, and autocomplete powered by ONS data.

Installation

dotnet add package TheCodeGuy.Postcode

Usage

using TheCodeGuy.Postcode;

// Create client with your API key
var client = new PostcodeClient("wt_your_api_key");

// Look up a postcode
var result = await client.LookupAsync("SW1A 1AA");
if (result != null)
{
    Console.WriteLine($"Country: {result.Country}");
    Console.WriteLine($"Coordinates: {result.Latitude}, {result.Longitude}");
}

// Validate a postcode
bool isValid = await client.ValidateAsync("SW1A 1AA");

// Bulk lookup (up to 100 postcodes)
var results = await client.BulkLookupAsync(new[] { "SW1A 1AA", "EC1A 1BB", "M1 1AE" });

// Find nearest postcodes to a location
var nearest = await client.NearestAsync(
    latitude: 51.5074,
    longitude: -0.1278,
    limit: 5,
    radiusMetres: 1000);

foreach (var pc in nearest)
{
    Console.WriteLine($"{pc.Postcode} - {pc.Distance}m away");
}

// Autocomplete suggestions
var suggestions = await client.AutocompleteAsync("SW1A", limit: 10);

Dependency Injection

Configure the client using dependency injection:

// In Program.cs or Startup.cs
services.AddPostcodeClient("wt_your_api_key");

// Or with custom options
services.AddPostcodeClient(options =>
{
    options.ApiKey = "wt_your_api_key";
    options.BaseUrl = "https://api.codeg.uy";
});

Then inject the client:

public class MyService
{
    private readonly PostcodeClient _postcodeClient;

    public MyService(PostcodeClient postcodeClient)
    {
        _postcodeClient = postcodeClient;
    }

    public async Task<string?> GetCountryForPostcode(string postcode)
    {
        var result = await _postcodeClient.LookupAsync(postcode);
        return result?.Country;
    }
}

API Methods

Method Description
LookupAsync(postcode) Look up a single postcode
BulkLookupAsync(postcodes) Look up multiple postcodes (max 100)
ValidateAsync(postcode) Check if a postcode exists
NearestAsync(lat, lng, limit, radius) Find postcodes near coordinates
AutocompleteAsync(partial, limit) Get postcode suggestions

License

This client library is licensed under the MIT License - you are free to use, modify, and distribute it.

Note: This library connects to The Code Guy API service at https://api.codeg.uy. While the library itself is free, API usage may be subject to rate limits. See the API documentation for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 269 12/16/2025