$ show dromara/forest
Dromara/forest is a declarative HTTP client framework for Java. It allows developers to define HTTP APIs via annotations on interfaces, similar to Retrofit for Android, but targeting the Java ecosystem with deep integration for Spring Boot and Solon. The core engine uses dynamic proxies to intercept interface invocations, builds HTTP requests from annotation metadata, and dispatches them to pluggable backends (Apache HttpClient, OkHttp3). It supports all HTTP methods, file upload/download, JSON/XML/Protobuf serialization, server-sent events (SSE), OAuth2 authentication, retry/redirect policies, cookie management, and async execution (including Kotlin coroutines and Project Reactor). The architecture is modular: a core library defines the annotation lifecycle, request/response models, converter abstractions, and interceptor chains, while separate modules provide Spring Boot auto-configuration, Solon plugin, JAXB/Jakarta XML converters, and a mock server for testing. The framework is designed for production use with customizable logging, SSL, proxy, and connection pooling. External dependencies include OkHttp3, Apache HttpClient, Jackson/Gson/Fastjson for JSON, and optional Reactor/Kotlin. The project includes extensive examples for integrating with AI APIs (ChatGPT, DeepSeek) and standard REST services.
The LLM identified 3 files worth highlighting for reuse:
A custom template engine that parses and evaluates dynamic strings containing placeholders, arithmetic expressions, function invocations, conditional (elvis) operators, and URL encoding. It supports both simple variable substitution ({name}) and complex expressions, making it the foundation for all dynamic attribute values in Forest annotations (URLs, headers, bodies). The implementation compiles templates into an AST of MappingExpr nodes (string, int, reference, dot, filter invoke, etc.) and evaluates them against a variable scope at request time. This is a standalone, non-trivial component that could be extracted for any Java project needing a lightweight expression language for string templates.
An in-memory cookie store that implements RFC-compliant cookie management: parsing Set-Cookie headers, matching cookies to requests by domain and path, handling expiration (removing expired cookies on each access), and supporting both session and persistent cookies. It uses a thread-safe ConcurrentHashMap partitioned by domain. The implementation is clean, well-encapsulated (depends only on ForestCookie, no internal imports), and demonstrates proper cookie specification handling. It can be extracted as a standalone cookie jar for any HTTP client.
Handles the full OAuth2 client credentials/token lifecycle: acquires tokens from the authorization server, caches them, refreshes before expiry, and ensures thread-safe concurrent access (synchronized block with double-checked locking). It supports custom token handlers and OAuth2 server definitions. The pattern is reusable for any Java client that needs automatic OAuth2 token management with caching and refresh logic.