Unirest is a simplified, lightweight HTTP client library for Java. This is a multi-module Maven project requiring Java 11+.
- unirest (unirest-java-core): Core HTTP client library
- unirest-modules-gson: GSON JSON object mapper integration
- unirest-modules-jackson: Jackson 3.x JSON object mapper integration
- unirest-modules-jackson-legacy: Jackson 2.x JSON object mapper integration
- unirest-modules-mocks: Mock client for testing Unirest-based code
- unirest-bdd-tests: Behavioral/integration tests
- unirest-java-bom: Bill of Materials for dependency management
The following are automatically checked by checkstyle during the build. Do not flag these in PR reviews:
- Naming conventions: Constants, local variables, member names, method names, package names, parameters, static variables, and type names
- Import issues: Illegal imports (sun.* packages), redundant imports, unused imports
- Line length: Max 186 characters
- File length: Max 1100 lines
- Method length: Max 35 lines
- Method count: Max 50 public methods per class
- Parameter count: Max 5 parameters per method
- Nested if depth: Max 3 levels
- Braces requirement: All control structures require braces
- Hidden fields: Except in setters and constructor parameters
- Long literals: Must use uppercase 'L' suffix
- Forbidden patterns:
Calendar.getInstance(use Java 8+ DateTime API)System.out.println.printStackTrace()
All Java source files must include the MIT license header. This is enforced by maven-license-plugin.
- Use Java 8+ DateTime API instead of
Calendar - Proper exception handling (no printStackTrace)
- No direct console output (System.out)
- Prefer fluent/builder patterns (see
Config,HttpRequestclasses) - Use
Optionalfor nullable return values - Follow immutable patterns where practical
All contributions must include tests:
-
Unit Tests (
unirest/src/test/java/)- Test individual components in isolation
- Use JUnit 5 with Mockito for mocking
- Use AssertJ for assertions
-
Behavioral Tests (
unirest-bdd-tests/src/test/java/BehaviorTests/)- Integration tests against a mock server
- Tests extend
BddTestbase class - Mock server auto-resets between tests
- Test real HTTP scenarios end-to-end
- JUnit 5 (junit-jupiter)
- Mockito for mocking
- AssertJ for fluent assertions
- JSONAssert for JSON comparisons
- Custom
MockClientfrom unirest-modules-mocks
@ExtendWith(MockitoExtension.class)
class MyFeatureTest {
@InjectMocks
private MyClass underTest;
@Test
void shouldDoSomething() {
// Given / When / Then pattern
}
}class MyFeatureTest extends BddTest {
@Test
void canDoSomethingOverHttp() {
Unirest.config().someConfiguration();
var response = Unirest.get(MockServer.GET)
.asObject(RequestCapture.class);
assertEquals(200, response.getStatus());
}
}Unirest: Static entry point with primary instanceUnirestInstance: Configurable instance (supports multiple instances)Config: Configuration holder with fluent APIHttpRequest/BaseRequest: Request builder interface and implementationHttpResponse: Response wrapper with various body typesClient: HTTP client abstraction (JavaClient implementation)ObjectMapper: JSON serialization abstraction
- Add configuration option to
Configclass if needed - Implement feature in appropriate module
- Add unit tests in same module
- Add behavioral tests in
unirest-bdd-tests - Update documentation in
mkdocs/docs/if user-facing
mvn verifymvn clean install # Full build with tests
mvn package -DskipTests # Build without testsJaCoCo enforces minimum 60% code coverage on complexity.
- Maintain backwards compatibility - this is critical for the project
- All tests must pass (
mvn verify) - Checkstyle must pass (runs automatically during compile)
- Include both unit and behavioral tests for new features
- Update CHANGELOG.md for user-facing changes
- Update documentation in mkdocs/docs/ for new features
- Dependencies are managed in the parent pom.xml
- Test dependencies are inherited: JUnit 5, Mockito, AssertJ, Guava (test scope)
- Prefer existing dependencies over adding new ones
- All production dependencies should be carefully considered for size impact
- API documentation via Javadoc
- User documentation in
mkdocs/docs/ - Example code should be tested (reference behavioral tests)