Enterprise-grade IP Geolocation API client for Java applications
A high-performance, type-safe Java SDK for GeoIPAPI.com that provides real-time IP geolocation data for personalization, analytics, and security applications. Built with developer experience in mind.
- π― Type-Safe: Fully typed responses with compile-time safety
- β‘ High Performance: Optimized for enterprise-scale applications
- π Multiple Formats: Support for JSON, JSONP, XML, and YAML responses
- π Secure: Built-in security best practices and error handling
- π± Easy Integration: Simple, intuitive API design
- π‘οΈ Enterprise Ready: Production-ready with comprehensive error handling
- π Well Documented: Extensive documentation and examples
import org.openapis.openapi.GeoIp;
import org.openapis.openapi.models.operations.GetIpResponse;
// Initialize the SDK
GeoIp client = GeoIp.builder().build();
// Get current IP address
GetIpResponse response = client.geoIPEndpoints().getIp().call();
if (response.res().isPresent()) {
System.out.println("Current IP: " + response.res().get());
}
- Java 11 or later
- Gradle 6.0+ or Maven 3.6+
Add to your build.gradle
:
implementation 'org.geoipapi:geoip:0.0.1'
Add to your pom.xml
:
<dependency>
<groupId>org.geoipapi</groupId>
<artifactId>geoip</artifactId>
<version>0.0.1</version>
</dependency>
Clone the repository and build:
git clone https://github.com/geoipapi/geo-ip-java.git
cd geo-ip-java
# Unix/Linux/macOS
./gradlew build
# Windows
gradlew.bat build
To publish to your local Maven repository:
# Unix/Linux/macOS
./gradlew publishToMavenLocal -Pskip.signing
# Windows
gradlew.bat publishToMavenLocal -Pskip.signing
import org.openapis.openapi.GeoIp;
import org.openapis.openapi.models.operations.GetIpDataResponse;
public class GeoLocationExample {
public static void main(String[] args) {
GeoIp sdk = GeoIp.builder()
.serverURL("https://api.geoipapi.com")
.build();
try {
// Get detailed geolocation data
GetIpDataResponse response = sdk.geoIPEndpoints()
.getIpData()
.call();
if (response.responseGetJsonDataJsonGet().isPresent()) {
var geoData = response.responseGetJsonDataJsonGet().get();
System.out.println("Location data retrieved successfully!");
// Process geolocation data
}
} catch (Exception e) {
System.err.println("Error retrieving geolocation data: " + e.getMessage());
}
}
}
import org.openapis.openapi.models.errors.HTTPValidationError;
try {
GetIpDataResponse response = sdk.geoIPEndpoints().getIpData().call();
// Handle successful response
} catch (HTTPValidationError e) {
// Handle validation errors (422)
System.err.println("Validation error: " + e.getMessage());
} catch (Exception e) {
// Handle other API errors
System.err.println("API error: " + e.getMessage());
}
GeoIp sdk = GeoIp.builder()
.serverURL("https://custom-api-endpoint.com")
.build();
geo-ip-java/
βββ src/
β βββ main/java/
β β βββ org/openapis/openapi/
β β βββ GeoIp.java # Main SDK client
β β βββ models/ # Data models and DTOs
β β β βββ operations/ # Request/response models
β β β βββ errors/ # Error handling models
β β βββ utils/ # Utility classes
β βββ test/java/ # Test files
βββ docs/ # API documentation
βββ build.gradle # Gradle build configuration
βββ settings.gradle # Gradle settings
βββ README.md # This file
GeoIp.java
- Main SDK client class and entry pointmodels/operations/
- Request and response models for API operationsmodels/errors/
- Exception classes for error handlingdocs/
- Detailed API documentation and examples
Currently, no environment variables are required for basic usage. The SDK uses sensible defaults.
Enable debug logging for development:
// Enable request/response logging (development only)
SpeakeasyHTTPClient.setDebugLogging(true);
Redact sensitive headers from logs:
SpeakeasyHTTPClient.setRedactedHeaders(Arrays.asList("Authorization", "X-API-Key"));
Run the test suite:
# Run all tests
./gradlew test
# Run tests with coverage
./gradlew test jacocoTestReport
# Run specific test class
./gradlew test --tests "GeoIpTest"
Test results will be available in build/reports/tests/test/index.html
.
graph TD
A[GeoIp Client] --> B[GeoIPEndpoints]
B --> C[HTTP Client]
C --> D[GeoIPAPI.com]
B --> E[Request Models]
B --> F[Response Models]
B --> G[Error Handlers]
- Type Safety: All API responses are strongly typed
- Immutability: Response objects are immutable by design
- Error Handling: Comprehensive exception hierarchy
- Performance: Optimized HTTP client with connection pooling
- Extensibility: Builder pattern for easy configuration
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow Java naming conventions
- Write comprehensive tests for new features
- Update documentation for API changes
- Ensure all tests pass before submitting PR
This project follows standard Java coding conventions. Please ensure your code:
- Uses proper indentation (4 spaces)
- Includes JavaDoc comments for public methods
- Follows camelCase naming conventions
- Includes appropriate error handling
This project is licensed under the MIT License - see the LICENSE file for details.
- GeoIPAPI.com - For providing the excellent IP geolocation service
- Java Community - For the robust ecosystem and tools
- Contributors - Thank you to all who have contributed to this project