MaksimShimshon.RestCountries.Embedded 0.9.41

dotnet add package MaksimShimshon.RestCountries.Embedded --version 0.9.41
                    
NuGet\Install-Package MaksimShimshon.RestCountries.Embedded -Version 0.9.41
                    
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="MaksimShimshon.RestCountries.Embedded" Version="0.9.41" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MaksimShimshon.RestCountries.Embedded" Version="0.9.41" />
                    
Directory.Packages.props
<PackageReference Include="MaksimShimshon.RestCountries.Embedded" />
                    
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 MaksimShimshon.RestCountries.Embedded --version 0.9.41
                    
#r "nuget: MaksimShimshon.RestCountries.Embedded, 0.9.41"
                    
#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 MaksimShimshon.RestCountries.Embedded@0.9.41
                    
#: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=MaksimShimshon.RestCountries.Embedded&version=0.9.41
                    
Install as a Cake Addin
#tool nuget:?package=MaksimShimshon.RestCountries.Embedded&version=0.9.41
                    
Install as a Cake Tool

License: MPL 2.0

🌍 RestCountries C# Port

This C# library is a full port of the REST Countries Java API, preserving full compatibility with the original JSON structure (v3.1 and v3).

It provides strongly typed access to rich country and region data, ideal for .NET developers building apps that need detailed country-related information.

The package supports dependency injection for seamless integration into modern web applications.

It also includes high test coverage, making it production-ready.

🔑 Key Features

  • Access detailed country data: name, capital, region, population, area, and more
  • Retrieve languages, currencies, and translations of country names
  • Time zone support for all countries
  • Strongly typed models for easy C# integration
  • Fully compatible with original REST Countries JSON formats
  • Built-in support for ASP.NET dependency injection

Perfect for apps that need reliable, structured, and localized country information.

Important Information

Pakages

MaksimShimshon.RestCountries

alternate text is missing from this package README image alternate text is missing from this package README image

This .NET 8 based pakage contains the core behaviour for the RestCountries without any dependencies.

using MaksimShimshon.RestCountries;
using MaksimShimshon.RestCountries.Data;
var builder = WebApplication.CreateBuilder(args);
// this will make a singleton accessible through IRestCountries.
// replace RestCountriesEmbed.GetVersion("countriesV3.1") by your local or remote verson.json file.
builder.Services.AddRestCountriesServices(RestCountriesEmbed.GetVersion());

MaksimShimshon.RestCountries.Embedded

alternate text is missing from this package README image alternate text is missing from this package README image

📦 Package Size Consideration

The Embedded package includes all available JSON versions, which significantly increases its size.
This may not be suitable for front-end deployments due to payload concerns.

However, it is ideal for server-side use, where having access to multiple versions of the data can be valuable.

using MaksimShimshon.RestCountries;
using MaksimShimshon.RestCountries.Embedded;
var builder = WebApplication.CreateBuilder(args);
// this will make a singleton accessible through IRestCountries.
builder.Services.AddRestCountriesServices(RestCountriesEmbed.GetVersion("countriesV3.1"));

MaksimShimshon.RestCountries.Data

⚠️ Important Compatibility Notice

This package must not be installed alongside the MaksimShimshon.RestCountries.Embedded package.
A conflict has been intentionally introduced by using the same RestCountriesEmbed class in both packages to avoid incompatibility.

  • **Embedded** includes all available JSON versions.
  • **Data** includes only the targeted version.

As a result, the version of the Data package you install will match the version of the original REST Countries JSON data available in your project.

using MaksimShimshon.RestCountries;
using MaksimShimshon.RestCountries.Data;
var builder = WebApplication.CreateBuilder(args);
// this will make a singleton accessible through IRestCountries.
builder.Services.AddRestCountriesServices(RestCountriesEmbed.GetVersion());

Fields

You can check the FIELDS.md file to get info on each classes.

Getting Started

using MaksimShimshon.RestCountries.Embedded;

// Replace this to the json content of the version.json or use embeded content.
string jsonContentOfVersion = RestCountriesEmbed.GetVersion("countriesV3.1");
IRestCountries restCountries = new RestCountries(jsonContentOfVersion);
var countries = restCountries.GetAll();

Check if Postal Required

using MaksimShimshon.RestCountries.Embedded;

string jsonContentOfVersion = RestCountriesEmbed.GetVersion(version);
IRestCountries restCountries = new RestCountries(jsonContentOfVersion);
var countries = restCountries.GetAll();
var firstCountry = countries.First();
if (firstCountry.IsPostalRequired()) 
    Console.WriteLine($"{firstCountry.Name.Common} does require postal of format: {firstCountry.PostalFormat!.Format}");
else
    Console.WriteLine($"{firstCountry.Name.Common} does not require a postal.");

Fetch Country by ISO-2 & Validate its postal code

using MaksimShimshon.RestCountries.Embedded;

string jsonContentOfVersion = RestCountriesEmbed.GetVersion(version);
IRestCountries restCountries = new RestCountries(jsonContentOfVersion);
var countries = restCountries.GetAll();
// ca = Canada. You could also do CCA3 with CAN.
var firstCountry = restCountries.IsValidCCA2Code("ca");
if (restCountries.IsValidCCA2Code("ca"))
    if (restCountries.GetByCCA2Code("cA")!.IsPostalValid("H1A2T2")) 
        Console.WriteLine("H1A2T2 is a valid postal for Canada");
    else
        Console.WriteLine($"ca is not a valid country iso2.");

More to Explore

Explore the other functions

using MaksimShimshon.RestCountries.Embedded;

string jsonContentOfVersion = RestCountriesEmbed.GetVersion(version);
IRestCountries restCountries = new RestCountries(jsonContentOfVersion);
var countries = restCountries.GetAll();
if (restCountries.IsValidCCA2Code("ca")) Console.WriteLine("This is valid country code.");
if (restCountries.IsValidCCA3Code("can")) Console.WriteLine("This is valid country code.");
if (restCountries.IsValidCCA2PostalCode("ca", "H1T2S2")) Console.WriteLine("This is valid country code and postal.");
if (restCountries.IsValidCCA3PostalCode("can", "H1T2S2")) Console.WriteLine("This is valid country code and postal.");
if (restCountries.IsValidCCA2Currency("ca", "CAD")) Console.WriteLine("CAD is a valid Canadian Currency.");
if (restCountries.IsValidCCA3Currency("cad", "CAD")) Console.WriteLine("CAD is a valid Canadian Currency.");
if (restCountries.IsValidCCA3Currency("cad", "CAD")) Console.WriteLine("CAD is a valid Canadian Currency.");

var country = countries.First()!;
Console.WriteLine($"Phone Prefixes are {string.Join(',', country.PhonePrefixes())}");

Similar projects

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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
0.9.41 139 6/26/2025
0.9.4 140 6/18/2025