Skip to content

visus-io/AddressValidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

362 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AddressValidation

GitHub Actions Workflow Status Sonar Quality Gate Sonar Coverage

Static Badge

Package Version Downloads
VisusIO.AddressValidation NuGet Version NuGet Downloads
VisusIO.AddressValidation.Integration.FedEx NuGet Version NuGet Downloads
VisusIO.AddressValidation.Integration.Google NuGet Version NuGet Downloads
VisusIO.AddressValidation.Integration.PitneyBowes NuGet Version NuGet Downloads
VisusIO.AddressValidation.Integration.Ups NuGet Version NuGet Downloads

AddressValidation is a .NET library that provides a unified, provider-agnostic API for validating physical mailing addresses.

Note

AddressValidation supports trimming and native AOT deployments.

Integrations

Service Coverage Status
FedEx® Address Validation API 46 countries Status
Google Address Validation API 39 countries Status
Pitney Bowes Address Validation API United States Status
UPS® Address Validation API United States Status
USPS® Address Validation API United States Status

Quick Start

Installation

Install the integration package for your chosen provider via the .NET CLI:

dotnet package add VisusIO.AddressValidation.Integration.FedEx

Registration

All integrations require HybridCache for OAuth token caching. Register it alongside the integration at application startup:

builder.Services.AddHybridCache();
builder.Services.AddFedExAddressValidation();

Configuration

Configuration is read from appsettings.json under the AddressValidationSettings:<Provider> section. For FedEx:

{
  "AddressValidationSettings": {
    "FedEx": {
      "AccountNumber": "<your account number>",
      "ClientId": "<your client id>",
      "ClientSecret": "<your client secret>",
      "ClientEnvironment": "PRODUCTION"
    }
  }
}
Property Required Description
AccountNumber Yes Your FedEx account number
ClientId Yes OAuth 2.0 client ID
ClientSecret Yes OAuth 2.0 client secret
ClientEnvironment No PRODUCTION, DEVELOPMENT, or SANDBOX. Defaults to DEVELOPMENT

Important

ClientId and ClientSecret should be stored encrypted at rest. See Security in the documentation for recommended approaches.

Each provider has its own set of configuration properties. See the documentation for the full reference.

Usage

Inject IAddressValidationService<TRequest> into your service or controller and call ValidateAsync:

public class ValidateController
{
    private readonly IAddressValidationService<FedExAddressValidationRequest> _validationService;

    public ValidateController(IAddressValidationService<FedExAddressValidationRequest> validationService)
    {
        _validationService = validationService ?? throw new ArgumentNullException(nameof(validationService));
    }

    [HttpPost]
    public async Task<IActionResult> Post([FromBody] FedExAddressValidationRequest request, CancellationToken cancellationToken = default)
    {
        IAddressValidationResponse? response = await _validationService.ValidateAsync(request, cancellationToken);

        return response is null
            ? new NotFoundResult()
            : response.Errors.Count > 0
                ? new UnprocessableEntityObjectResult(response)
                : new OkObjectResult(response);
    }
}

Each integration package exposes its own TRequest type (e.g., FedExAddressValidationRequest, GoogleAddressValidationRequest) and a corresponding Add*AddressValidation() extension method. See the documentation for provider-specific options.

Documentation

Full documentation is available at https://ave.projects.visus.io/.

About

.NET library to provide a streamlined process of validating physical addresses leveraging the choice of provider (e.g., Google, PitneyBowes, FedEx, UPS).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages