A basic wrapper written for C# users.
This is a basic wrapper for the postcodes.io API, which can grab information about single postcodes and the raw JSON string for other manipulation. To get started, read the below guide.
First, clone the repo/download the .cs
files that aren't Program.cs
, and add them to your project by right clicking your project's name in the solution browser, then going to Add -> Existing Item
and finding the file inside your project folder.
When that's done, where you want to use the wrapper, add using PostcodeIO.API;
at the top of the file. This project also depends on Newtonsoft.JSON
, which you can install via. Nuget.
To get information for an individual postcode, you can do this:
//Test a basic postcode.
var pcinfo = PostcodeAPIFetcher.GetPostcodeInfo("FK6 6BL");
//Print some information.
Console.WriteLine("This postcode is in country:");
Console.WriteLine(pcinfo.country);
Console.WriteLine("This postcode is in region:");
Console.WriteLine(pcinfo.region);
To get a raw response for an individual postcode, you can do this:
string contents = PostcodeAPIFetcher.GetRawResponse("FK6 6BL");
This wrapper has the same structure as the JS version, so you can just go to the official docs, or you can go inside the PostcodeInfo.cs
file to see commented docs.