SunAuto.Usps.Client 1.0.1-preview

This is a prerelease version of SunAuto.Usps.Client.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package SunAuto.Usps.Client --version 1.0.1-preview
                    
NuGet\Install-Package SunAuto.Usps.Client -Version 1.0.1-preview
                    
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="SunAuto.Usps.Client" Version="1.0.1-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SunAuto.Usps.Client" Version="1.0.1-preview" />
                    
Directory.Packages.props
<PackageReference Include="SunAuto.Usps.Client" />
                    
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 SunAuto.Usps.Client --version 1.0.1-preview
                    
#r "nuget: SunAuto.Usps.Client, 1.0.1-preview"
                    
#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 SunAuto.Usps.Client@1.0.1-preview
                    
#: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=SunAuto.Usps.Client&version=1.0.1-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SunAuto.Usps.Client&version=1.0.1-preview&prerelease
                    
Install as a Cake Tool

Sun Auto USPS API Client

A simple .NET client/SDK for the USPS API.

This supports USPS API V3 only.

In situations there is a need to deal with mailing addresses, the USPS API can be a useful tool to standardize and validate addresses. This can amount to cost savings when dealing with shipping service companies.

Installation

Use the dotnet CLI, VSCode Solution explorer, or VS package manager to install:

SunAuto.Usps.Client

The package has limited coverage of the API and is still in preview.

Usage

The client expects a IConfigurationSection in the form:

{
  "Usps":{
    "ClientId": "your-client-id",
    "ClientSecret": "your-client-secret",
    "BaseUrl": "USPS API Base URL"
  }
}

If you are using an Azure Function, you can set the configuration in the local.settings.json file or in the Azure portal under Application Settings.

{
  "Usps:ClientId": "your-client-id",
  "Usps:ClientSecret": "your-client-secret",
  "Usps:BaseUrl": "USPS API Base URL"
}

Inject the class of your choice into your application's service collection along with the HTTP client:

services.AddHttpClient();
services.AddScoped<Addresses>();

Currently, only the standardized address and city & state by zip code is implemented which returns the best standardized address for a given address.

Successful requests will return a response object specific to the data which the API returns. For example, the Addresses class will return a StandardizedAddressResponse object.

Errors will throw a ArgumentException with a message indicating the error and more detailed information in an object added to the Data collection property of the exception containing error information deserialized from the error response, e.g.,

{
    "apiVersion": "/addresses/v3/",
    "error": {
        "code": "400",
        "message": "OASValidation OpenAPI-Spec-Validation-Addresses-Request with resource oas://addresses_v3.yaml: failed with reason: [ERROR - ECMA 262 regex ^(AA|AE|AL|AK|AP|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MP|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY)$ does not match input string tx: []]",
        "errors": [
            {
                "title": "openapi_validation_error",
                "detail": "The API request or response does not validate against the specification.",
                "source": "API"
            }
        ]
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

USPS Developer Portal APIs

Support

If you like this project and think it has helped in any way, consider getting tires or auto service at a Sun Auto Tire & Service location near you:

<a href="https://sun.auto/home" target="_blank"><img src="https://sun.auto/wp-content/themes/sun-auto/images/logo_sunauto.png" alt="Sun Auto Tire & Service" width="150" height="65"/></a>

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.1.0-preview 112 6/30/2025
1.0.1-preview 54 6/27/2025
1.0.0-preview 58 6/27/2025

Preview release