wireform-grpc
wireform-grpc is a native Haskell implementation of gRPC. gRPC is the
standard RPC layer for microservices that already speak Protocol Buffers.
Use this package when you need a pure-Haskell client or server with unary
and streaming call patterns, without binding to the C++ gRPC core library.
The library is vendored from grapesy
by Edsko de Vries (Well-Typed) and integrated into the wireform monorepo so
service codegen targets a known in-tree binding.
Key features
Section titled “Key features”- Client and server under
Network.GRPC.ClientandNetwork.GRPC.Server - Unary and streaming RPCs: server streaming, client streaming, and bidirectional streaming
- HTTP/2 transport via the in-tree
wireform-http2engine - TLS with certificate store helpers
- Message compression negotiation
- Protobuf and JSON codecs through
Network.GRPC.Common.ProtobufandNetwork.GRPC.Common.JSON - OpenTelemetry instrumentation via
Network.GRPC.Client.OtelandNetwork.GRPC.Server.Otel
Basic usage
Section titled “Basic usage”A minimal unary client call. Protobuf service types come from
wireform-proto codegen or a Proto.TH.loadProto splice:
import Network.GRPC.Clientimport qualified Network.GRPC.Client.StreamType.IO as IOimport Network.GRPC.Commonimport Network.GRPC.Common.Protobuf
import qualified Routeguide.Service.RouteGuide as RG
main :: IO ()main = do let server = ServerInsecure (Address "localhost" 50051 Nothing) withConnection def server $ \conn -> do feature <- IO.nonStreaming conn (rpc @(Protobuf RG.RouteGuide "GetFeature")) (defMessage & RG.point .~ pt 408000000 (-743000000)) print feature where pt lat lon = defMessage & RG.latitude .~ lat & RG.longitude .~ lonFor server-side handlers, use Network.GRPC.Server.Run with handlers
constructed from Network.GRPC.Server.StreamType:
import Network.GRPC.Server.Runimport Network.GRPC.Server.StreamType
runGuideServer :: IO ()runGuideServer = runServerWithHandlers def config handlers where config = ServerConfig { serverInsecure = Just (InsecureConfig (Just "0.0.0.0") 50051) , serverSecure = Nothing } handlers = [ fromMethod (mkNonStreaming handleGetFeature) ]Wrap calls with Network.GRPC.Client.Otel.withTracedRPC when you need
distributed tracing spans around RPC latency.
Notable modules
Section titled “Notable modules”| Module | Purpose |
|---|---|
Network.GRPC.Client | Connection management, withConnection, withRPC |
Network.GRPC.Client.StreamType.IO | Unary and streaming client handlers |
Network.GRPC.Server | Server handler registration and call dispatch |
Network.GRPC.Server.Run | Server lifecycle and listener setup |
Network.GRPC.Common.Protobuf | Protobuf codec integration with wireform-proto |
Network.GRPC.Common.Compression | Compression negotiation |
Network.GRPC.Client.Otel / Network.GRPC.Server.Otel | OpenTelemetry hooks |
Network.GRPC.Util.TLS | Certificate store and TLS helpers |
Module naming
Section titled “Module naming”This package follows grapesy’s Network.GRPC.* module layout rather than
wireform’s <Format>.* convention, so existing grapesy imports continue to
work after the vendored migration.