mainCepSearch is a Java application designed to validate and retrieve information about Brazilian postal codes (CEPs) using the CEP Aberto API. The application prompts the user to input a CEP, validates it, and if valid, queries the CEP Aberto API to fetch details about the location associated with the CEP.
- Validates Brazilian CEP format.
- Uses the CEP Aberto API to fetch location information.
- Displays the city and state of the provided CEP.
- Handles and displays error messages for invalid CEPs and API errors.
- A valid CEP Aberto API token
-
Run the application
-
Input a CEP:
- When prompted, enter a valid Brazilian CEP (e.g., 01001000).
mainCepSearch: Main class containing the application's entry point.CepInfo: Model class to map the JSON response from the CEP Aberto API.CepValidator: Utility class for validating CEP format.EnvLoader: Utility class for loading environment variables from a.envfile.
-
Running the application:
mvn exec:java -Dexec.mainClass="mainCepSearch" -
Entering a CEP:
Por favor, insira um CEP: 01001000 -
Expected Output:
São Paulo-SP
-
If an invalid CEP is entered:
O CEP inserido é inválido: 12345678 -
If there is an error with the API request (e.g., invalid token or network issue):
Error: 401 Error message: Unauthorized
gson: For parsing JSON responses from the API.java.net.http.HttpClient: For making HTTP requests to the CEP Aberto API.