The Common Address API is an ASP.NET Core web application designed for address validation using the HERE Platform geocode API. It provides endpoints for validating full addresses, postal codes, and location subqueries. The project is built with .NET 9, containerized via Docker for easy deployment, and includes OpenAPI documentation for API exploration. It supports custom JSON conversion for enum-keyed dictionaries and asynchronous validation workflows.
- Language: C# (.NET 9)
- Framework: ASP.NET Core
- Containerization: Docker
- API Documentation: OpenAPI with Swagger UI
- License: [Specify license, e.g., MIT] (update as needed)
- Asynchronous validation of full user addresses using the HERE Platform.
- Validation of US postal codes (5 or 9 digits).
- Location validation via subqueries, supporting both dictionary-based and list-based inputs.
- SubqueryTypes
public enum SubqueryType { country, state, county, city, district, street, houseNumber, postalCode }
- Custom JSON converter for handling enum-keyed dictionaries (e.g., for subquery types like country, state, postal code).
- Configurable endpoints and base URIs via
appsettings.json. - Dockerized setup for consistent local and production environments.
- Docker: Required for building and running the container. Download Docker Desktop from https://www.docker.com/products/docker-desktop/.
- Windows: The provided BAT script is optimized for Windows.
- curl: Available in Windows 10+ for endpoint testing (optional for manual verification).
- HERE API Key: A valid API key from the HERE Platform is required for address validation features.
- The ZIP file
DevApiKey.7zipcontains an installer that sets up a development environment, including configuring the HERE API key as an environment variable (ADDRESS_API_KEY). - Extract and run the installer to prepare your local machine. This ensures the API key is securely set for running the project without hardcoding sensitive information.
If using Git:
git clone https://github.com/yourusername/common-address-api.git
cd common-address-apiAlternatively, download and extract the source code.
- The
Run Docker Container.batscript automates the process:- Checks for Docker installation and directs you to download if missing.
- Stops and removes any existing container or image tagged
common-address-api. - Builds a new Docker image from the
Dockerfile. - Runs the container, mapping host port 8080 to container port 80.
- Waits for the API to start and performs basic tests on endpoints.
- Opens the Swagger UI in your default browser.
- Run the script:
"Run Docker Container.bat"
- Build the Docker image:
docker build -t common-address-api . - Run the container:
docker run -d -p 8080:80 --name common-address-api common-address-api
- Verify the API is running by accessing
http://localhost:8080/swagger/index.html.
Access the API at http://localhost:8080. Use the Swagger UI at http://localhost:8080/swagger/index.html for interactive documentation and testing.
-
POST /ValidateUserAddress/ValidateAddress
- Validates a full user address using the HERE Platform.
- Request body:
UserAddressobject. - Response:
200 OKwith validatedRootObjector404 Not Found. - expected document format
UserAddress
{ "street": "string", //required "city": "string", //required "state": "string", //required "zipCode": "string", //required "country": "string" //required }
-
POST /ValidateUserAddress/{postalCode}
- Validates a US postal code (5 or 9 digits).
- Path parameter:
postalCode(e.g.,12345or123456789). - Response:
200 OKif valid,400 Bad Requestwith error details if invalid. /ValidateUserAddress/12345[6789]
-
POST /ValidateUserAddress/AddressSubquery/Dictionary
- Validates location using a list of subquery dictionaries.
- Request body:
Subquery- Subqery Object
Dictionary<SubqueryType, string> - Response:
200 OKif valid,400 Bad Requestwith error details if invalid. - expected document format
Subquery
{ "city": "Chicago", }
-
POST /ValidateUserAddress/AddressSubquery/List
- Validates location using a structured
SubqueryListobject. - Request body:
SubqueryList. - Response:
200 OKif valid,400 Bad Requestwith error details if invalid. - expected document
SubqueryList
{ "items": [ { "subquery": {"state": "ga"} }, { "subquery": {"postalCode": "30082"} } ] }; - Validates location using a structured
- Update
appsettings.jsonfor HERE API settings and Kestrel endpoints. - Example:
{ "Here": { "ApiKey": "TEST KEY", "BaseUri": "https://geocode.search.hereapi.com/v1", "GeocodeEndpoint": "/geocode" }, "Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:80" } } } } - The API key is loaded from the
ADDRESS_API_KEYenvironment variable for security.
Controllers/: API controllers (e.g.,ValidateUserAddress.cs).Enumerators/: Enums for subquery types (e.g.,SubqueryType.cs).Helper/: Custom JSON converters (e.g.,EnumKeyDictionaryConverter.cs).Work/: Validation logic (e.g.,HerePlatformValidator.cs).Program.cs: Application entry point and middleware configuration (OpenAPI, Swagger UI, controllers).appsettings.json: Configuration settings.Dockerfile: Multi-stage Docker build for .NET 9 SDK and runtime..dockerignore: Excludes build artifacts (e.g.,bin/,obj/).Run Docker Container.bat: Automation script for Docker setup and testing.
- ASP.NET Core for web framework.
- Newtonsoft.Json for JSON handling.
- NSwag for OpenAPI/Swagger documentation.
- Use the
Run Docker Container.batscript for automated endpoint tests viacurl. - For custom tests, use tools like Postman or the Swagger UI to send requests to the validation endpoints.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/awesome-feature). - Commit changes (
git commit -m "Add awesome feature"). - Push to the branch (
git push origin feature/awesome-feature). - Open a Pull Request.
AI Tools
- Copilot
- read log reports
- setup docker environment steps
- identify best practices for api key secrets for dev
- troubleshoot json document
- validate dictionary with enum comparison
- Grok
- QA for Copilot Dockerfile
- troubleshooting docker image
- troubleshooting Swagger UI
- this readme doc
- developing bat file for automated launces