$ show dreamhead/moco
Moco is a Java library and standalone server for creating mock HTTP servers, primarily used for integration testing. It supports HTTP/HTTPS, REST, WebSocket, SSE, CORS, proxy with failover/playback, recording/replaying, and template-based responses. Architecture is modular: moco-core provides interfaces and implementations (Netty-based server, request matchers, response handlers), moco-runner adds a CLI for JSON-based configuration and standalone execution, and moco-junit/moco-junit5 provide JUnit integration. The system is configured either via a fluent Java API (central `Moco` static factory) or JSON configuration files, making it easy to stub endpoints in tests or as a standalone mock service. It uses Netty for high-performance HTTP serving, Jackson for JSON processing, Freemarker for templates, and Guava for utilities. The codebase is well-structured with clear separation of concerns, extensive tests, and support for modern protocols like HTTP/2 and WebSocket.
The LLM identified 2 files worth highlighting for reuse:
A self-contained implementation of Ant-style path pattern matching (e.g., `/**` , `{variable}`). It has no dependencies on any Moco internal interfaces and can be extracted directly into any Java project needing URL or file path matching. The implementation is clean, well-tested, and follows the same pattern as Spring's AntPathMatcher but is entirely standalone.
Parses server-sent event (SSE) text into structured SseEvent objects (id, event, data, retry, comments). It is a small, focused parser with no internal dependencies, making it reusable across any project that needs to parse SSE streams. The parsing logic handles multi-line data fields and optional fields correctly.