Production-ready HTTP + JSON client for Java 21+ and Kotlin
A pure, stateless library that eliminates boilerplate while providing automatic JSON parsing, virtual threads support, and production-safe defaults.
// Installation
implementation("io.github.mochaapi:MochaJSON:1.0.0")
// Usage - that's it!
Map<String, Object> data = Api.get("https://api.example.com/users/1")
.execute()
.toMap();Problem Statement:
- Tired of OkHttp + Gson boilerplate?
- Need simple HTTP requests without framework overhead?
- Want production-ready stability guarantees?
Solution:
- One import, zero configuration
- Automatic JSON parsing
- Production-safe defaults
- API stability guarantees
- β Zero Boilerplate - One line API calls
- β Production Ready - Stability guarantees for 1.x.x
- β Pure Library - No lifecycle management
- β Java 21+ & Kotlin - Full support for both
- β Virtual Threads - Built-in async support
- β Type Safe - Automatic POJO mapping
- β Interceptors - Request/Response hooks
- β Retry Logic - Exponential backoff
- β Security - URL validation, localhost control
- β Lightweight - Minimal dependencies
Gradle (Kotlin DSL):
dependencies {
implementation("io.github.mochaapi:MochaJSON:1.0.0")
}Gradle (Groovy):
dependencies {
implementation 'io.github.mochaapi:MochaJSON:1.0.0'
}Maven:
<dependency>
<groupId>io.github.mochaapi</groupId>
<artifactId>MochaJSON</artifactId>
<version>1.0.0</version>
</dependency>Java Example:
import io.mochaapi.client.*;
public class QuickStart {
public static void main(String[] args) {
// Simple GET request
Map<String, Object> user = Api.get("https://jsonplaceholder.typicode.com/users/1")
.execute()
.toMap();
System.out.println("Name: " + user.get("name"));
// POST request with body
ApiResponse response = Api.post("https://jsonplaceholder.typicode.com/posts")
.body(Map.of("title", "Hello", "body", "World", "userId", 1))
.execute();
System.out.println("Status: " + response.code());
}
}Kotlin Example:
import io.mochaapi.client.*
fun main() {
// Simple GET request
val user = Api.get("https://jsonplaceholder.typicode.com/users/1")
.execute()
.toMap()
println("Name: ${user["name"]}")
// POST with data class
data class Post(val title: String, val body: String, val userId: Int)
val response = Api.post("https://jsonplaceholder.typicode.com/posts")
.body(Post("Hello", "World", 1))
.execute()
println("Status: ${response.code()}")
}Chainable JSON Access:
import io.mochaapi.client.*;
// Clean nested JSON access without casting
String city = Api.get("https://api.example.com/user/123")
.execute()
.toJsonMap()
.get("data").get("location").get("city").toString();Production-Ready Features:
// No initialization required
// No shutdown needed
// Each client is independent
ApiClient client1 = new ApiClient.Builder().build();
ApiClient client2 = new ApiClient.Builder().build();
// Use them independently - no conflicts!public class User {
public int id;
public String name;
public String email;
}
User user = Api.get("https://api.example.com/users/1")
.execute()
.to(User.class);// CompletableFuture
CompletableFuture<ApiResponse> future = Api.get(url).executeAsync();
// Callbacks
Api.get(url).executeAsync(response -> {
System.out.println("Got: " + response.code());
});ApiClient client = new ApiClient.Builder()
.connectTimeout(Duration.ofSeconds(10))
.readTimeout(Duration.ofSeconds(30))
.enableRetry() // 3 attempts with exponential backoff
.allowLocalhost(true) // For development
.requestInterceptor(req -> {
req.header("Authorization", "Bearer " + token);
return req;
})
.build();- π Full Documentation - Complete guide
- π Getting Started - Quick setup
- π Java Examples - Java code samples
- π Kotlin Examples - Kotlin code samples
- π§ API Reference - Complete API docs
- π Security - Security policy
- π Changelog - Version history
MochaJSON is open source and free to use. If it helps your project, consider sponsoring to support ongoing development and maintenance.
Why Sponsor?
- β Ensure long-term maintenance and updates
- β Priority support for issues and feature requests
- β Influence roadmap and feature priorities
- β Recognition in README and documentation
- β Support open source software
Become a Sponsor on GitHub Sponsors
Other Ways to Support:
- β Star the repository
- π Report bugs and suggest features
- π Contribute code or documentation
- π¬ Share on social media
- π’ Write a blog post or tutorial
For enterprise support, custom features, or bulk licensing, contact us at:
- π§ Email: kashvi0712@proton.me
- πΌ GitHub: Enterprise Contact
| Feature | MochaJSON | OkHttp + Gson | Retrofit |
|---|---|---|---|
| Setup Lines | 1 | 20+ | 30+ |
| Dependencies | 1 | 3+ | 4+ |
| JSON Parsing | Automatic | Manual | Converter setup |
| Kotlin Support | Native | Limited | Requires setup |
| Virtual Threads | β Built-in | β Manual | β Manual |
| Stateless | β Yes | ||
| Retry Logic | β Built-in | β Manual | β Manual |
| API Stability | β Guaranteed |
- Java: 21+ (LTS recommended)
- Kotlin: 1.9.22+ (optional, for Kotlin projects)
- Dependencies: Minimal
- Jackson 2.17.2 (JSON for Java)
- Kotlinx Serialization 1.7.2 (JSON for Kotlin)
- SLF4J 2.0.9 (optional logging)
MochaJSON v1.0.0 provides strict API stability guarantees:
β No breaking changes in 1.x.x releases β Semantic versioning strictly followed β Deprecation warnings 6+ months before removal β Long-term support commitment
Get Involved:
- π Report Issues
- π‘ Request Features
- π€ Contribute Code
- π¬ Join Discussions
- π Read Contributing Guide
Code of Conduct: We follow the Contributor Covenant to ensure a welcoming community.
MochaJSON is released under the MIT License.
MIT License - Free to use, modify, and distribute
β
Commercial use allowed
β
Modification allowed
β
Distribution allowed
β
Private use allowed
Built With:
- Java 21 Virtual Threads
- Jackson for JSON processing
- Kotlinx Serialization for Kotlin
- Love for clean, simple APIs
Inspired By:
- The need for simpler HTTP clients
- Community feedback and requests
- Production use cases and requirements
Need Help?
- π Documentation
- π¬ GitHub Discussions
- π Issue Tracker
- π§ Email: support@mochaapi.org
Follow Updates:
- π Star on GitHub
- π Watch repository for releases
- π’ Follow @MochaAPI (if available)
Made with β€οΈ by the MochaAPI Team
Star β this repository if you find it useful!