Show HN: I built a JSON-RPC library for Zig with compile time reflection
10 months ago
- #Zig
- #Library
- #JSON-RPC
- ZigJR is a lightweight Zig library for JSON-RPC 2.0 with message streaming and native function handlers.
- Features include parsing/composing JSON-RPC messages, batch requests/responses, and message streaming via delimiters or Content-Length headers.
- Supports Request, Response, Notification, and Error message types in JSON-RPC 2.0.
- Includes a flexible logging mechanism for debugging and inspecting JSON-RPC messages.
- Provides examples for quick start, including hello.zig for basic usage and mcp_hello.zig for MCP server implementation.
- Installation involves fetching the library via zig fetch and integrating it into build.zig.
- Handler functions can be global, struct-scoped, or instance-scoped, with automatic type mapping from JSON to Zig types.
- Memory management is handled automatically for handlers, with cleanup performed post-request.
- Custom dispatchers can be implemented for specialized handling of RPC messages.
- Examples demonstrate streaming API usage, RPC pipeline processing, and manual message parsing/composing.