gRPC
apitwin supports gRPC mock and proxy alongside the HTTP server — both run in the same process, activated by --grpc-proto.
How it works
- Provide one or more
.protofiles via--grpc-proto— noprotocor code generation required - Define
[[grpc_routes]]in your config files alongside existing[[routes]] - apitwin starts a gRPC server on
--grpc-port(default 50051) and an HTTP server on--port(default 4000) - Incoming gRPC calls are matched by full method path, decoded from protobuf to JSON for condition evaluation, and the stub response is encoded back to protobuf wire format
- Unmatched calls are forwarded to
--grpc-targetif set, or returnUNIMPLEMENTED
Key features
- No protoc — apitwin parses
.protofiles at runtime using reflection - Unary mocking — stub responses with protojson (JSON with proto field names)
{body.field}interpolation — dynamic file paths from request body fields (e.g.stubs/{body.id}.json)- Directory wrapping — directory aggregation auto-wraps into the correct response field for list RPCs
- Condition routing — route calls to different cases based on request body fields
- Proxy fallthrough — forward unmatched methods to an upstream gRPC server
- Directory persistence — stateful CRUD operations on directory-based stub files
- Transitions — time-based response progression, same as HTTP
- Server reflection —
grpcurlandgrpc-uiwork out of the box - Import paths —
--import-pathflag for resolving proto imports from shared directories
Documentation
| Page | Description |
|---|---|
| Quick Start | Get a gRPC mock server running in minutes |
| Configuration | [[grpc_routes]] format, match patterns, status codes |
| Stubs & Conditions | Stub format, conditions, proxy fallthrough |
| Persistence | Directory-based CRUD for gRPC |
| Generation | apitwin generate --proto workflow |