MochaJSON — Unified HTTP & JSON Client for Java & Kotlin
The simplest way to make HTTP requests and parse JSON in Java & Kotlin - Now with v1.0.0 featuring production-ready stability guarantees!
Stop juggling OkHttp, Gson, and custom parsers. MochaJSON v1.0.0 unifies HTTP requests and JSON parsing into a single, fluent API that works seamlessly across both Java and Kotlin projects. This lightweight library eliminates boilerplate while focusing on simplicity and ease of use.
// Basic usage - One line to rule them all
Map<String, Object> user = Api.get("https://api.github.com/users/octocat").execute().toMap();
// Advanced usage with v1.0.0 simplified features
ApiClient client = new ApiClient.Builder()
.connectTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofSeconds(30))
.enableRetry() // 🆕 Simple retry with 3 attempts
.allowLocalhost(true) // 🆕 Development-friendly security
.addRequestInterceptor(RequestInterceptor.bearerAuth(() -> getToken()))
.build();
CompletableFuture<ApiResponse> future = client.get("https://api.github.com/user")
.executeAsync();
Why Choose MochaJSON Over OkHttp + Gson?
Traditional Java HTTP clients require multiple dependencies and verbose boilerplate. You need OkHttp for requests, Gson for JSON parsing, custom error handling, retry logic, and connection pooling. MochaJSON eliminates this complexity by providing a unified API that handles everything automatically.
Instead of writing 20+ lines of setup code, you get clean, readable requests that work identically in Java and Kotlin. This makes MochaJSON the perfect OkHttp alternative and Gson alternative for modern Java development.
// Traditional approach: OkHttp + Gson (20+ lines of boilerplate)
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.connectionPool(new ConnectionPool(5, 5, TimeUnit.MINUTES))
.build();
Gson gson = new Gson();
Request request = new Request.Builder()
.url("https://api.example.com/user/123")
.build();
Response response = client.newCall(request).execute();
String json = response.body().string();
User user = gson.fromJson(json, User.class);
// MochaJSON approach: 1 line with automatic JSON parsing + simplified features
User user = Api.get("/api/user/123").execute().to(User.class);
MochaJSON vs Traditional Java HTTP Client Stack
| Traditional Stack | MochaJSON HTTP Client |
|---|---|
| OkHttp + Gson + Custom Parsers | Single dependency |
| 20+ lines per request | 1-3 lines per request |
| Manual error handling | Automatic exception mapping |
| Separate Java/Kotlin code | Unified API for both languages |
| Complex async setup | Built-in async support with virtual threads |
| Multiple imports | One import statement |
| Heavy dependencies | Lightweight footprint |
| Manual timeout configuration | Configurable timeouts with builder pattern |
| No built-in interceptors | Request/Response interceptors |
| Limited security features | Simple security controls |
| Manual connection pooling | 🆕 Automatic connection pooling (Java HttpClient) |
| No retry mechanism | 🆕 Simple retry with fixed delay |
| Complex configuration | 🆕 Simplified configuration |
| Verbose setup | 🆕 Minimal setup required |
Core Features of MochaJSON
🚀 Fluent API Design
Chainable request builder with intuitive syntax that reads like natural language. Perfect for building REST clients in Java and Kotlin.
📦 Automatic JSON Parsing
Parse JSON to Map, List, or POJO objects with zero configuration required. No more manual JSON parsing headaches.
⚡ Modern Async Support
Execute requests asynchronously with virtual threads (Java 21+), CompletableFuture, or callbacks. Built for modern Java and Kotlin applications.
🔗 Cross-Language Compatibility
Works identically in Java and Kotlin with full interoperability and type safety. One library, two languages.
🛡️ Enhanced Security
URL validation, hardened JSON parsing, and input sanitization. Protection against common security vulnerabilities.
🔧 Advanced Configuration
Configurable timeouts, interceptors, and logging with the new ApiClient builder pattern. Enterprise-ready features.
📱 Zero Boilerplate Setup
One import, no setup required. Start making API calls immediately with this lightweight Java JSON parser.
🎯 Type-Safe Operations
Compile-time type checking with generic support for POJOs and collections. Type safety without the complexity.
⚖️ Lightweight Performance
Minimal dependencies and small footprint compared to traditional HTTP client stacks. Faster than OkHttp + Gson.
🆕 New in v1.0.0
- Simplified API: Removed complex features to focus on core HTTP + JSON functionality
- Basic Retry: Simple retry mechanism with configurable attempts and fixed delay
- Security Controls: Simple localhost access control for development vs production
- Lightweight: Reduced library size and complexity for better performance
- Focused: Essential features only - no enterprise bloat
✨ Core Features
- Virtual threads support for Java 21+
- Request/Response interceptors
- Configurable timeouts with builder pattern
- Automatic JSON parsing
- Async operations with CompletableFuture
- Improved async APIs with CompletableFuture
Installation & Setup
Gradle (Recommended)
Add MochaJSON to your Java or Kotlin project with Gradle:
implementation("io.github.mochaapi:MochaJSON:1.0.0")
Maven
Include MochaJSON in your Maven project:
<dependency>
<groupId>io.github.mochaapi</groupId>
<artifactId>MochaJSON</artifactId>
<version>1.0.0</version>
</dependency>
Optional Dependencies
For logging support, add SLF4J:
implementation("org.slf4j:slf4j-api:2.0.9")
📦 Available on Maven Central
Quick Start Guide
Make your first API call in seconds with MochaJSON's fluent HTTP client:
import io.mochaapi.client.*;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
// Basic usage - GET request with automatic JSON parsing
Map<String, Object> response = Api.get("https://jsonplaceholder.typicode.com/posts/1")
.execute()
.toMap();
System.out.println("Title: " + response.get("title"));
// Advanced usage with v1.0.0 production features
ApiClient client = new ApiClient.Builder()
.connectTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofSeconds(30))
.enableConnectionPooling() // 🆕 Connection reuse
.enableRetryPolicy() // 🆕 Automatic retries
.enableCircuitBreaker() // 🆕 Fault tolerance
.enableCaching() // 🆕 HTTP caching
.enableLogging()
.addRequestInterceptor(RequestInterceptor.bearerAuth(() -> getToken()))
.build();
// Async request with CompletableFuture
CompletableFuture<ApiResponse> future = client.get("https://jsonplaceholder.typicode.com/posts")
.executeAsync();
ApiResponse result = future.get();
Map<String, Object> data = result.toMap();
Real-World Use Cases
MochaJSON excels in these common Java and Kotlin development scenarios:
- REST API Integration: Perfect for consuming REST APIs with automatic JSON parsing
- Microservices Communication: Lightweight HTTP client for service-to-service calls
- Mobile App Backend: Kotlin HTTP client for Android applications
- Spring Boot Applications: Drop-in replacement for RestTemplate with better performance
- Data Pipeline Processing: Efficient JSON parsing for ETL operations
Frequently Asked Questions
Can I use MochaJSON with Spring Boot?
Yes! MochaJSON works seamlessly with Spring Boot applications. It's a lightweight alternative to RestTemplate and WebClient.
Does MochaJSON support async operations?
Absolutely! MochaJSON v1.0.0 provides modern async support with virtual threads (Java 21+), CompletableFuture, callbacks, and reactive streams for non-blocking operations.
Is MochaJSON compatible with Kotlin?
Yes! MochaJSON is designed for both Java and Kotlin with full interoperability and type safety.
Documentation & Resources
- 🚀 Getting Started — Complete setup guide and basic usage patterns
- ⚖️ vs Alternatives — Compare MochaJSON with OkHttp, Gson, RestTemplate
- 📖 Java Examples — Comprehensive Java usage examples and best practices
- 📖 Kotlin Examples — Kotlin-specific examples and coroutine integration
- 🔧 Advanced Features — Connection pooling, retry, circuit breaker, caching
- ✅ Best Practices — Production deployment guide
- 📚 API Reference — Complete API documentation and method reference
- 🔄 Migration Guides — Migrate from other HTTP clients
- 🤝 Contributing — How to contribute to the MochaJSON project
External Resources
- 📦 Maven Central Repository — Download MochaJSON
- 🐙 GitHub Repository — Source code and issues
- 📚 JavaDocs — API documentation
MIT Licensed • Made with ❤️ for the Java and Kotlin community