Skip to content

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.

  • Client and server under Network.GRPC.Client and Network.GRPC.Server
  • Unary and streaming RPCs: server streaming, client streaming, and bidirectional streaming
  • HTTP/2 transport via the in-tree wireform-http2 engine
  • TLS with certificate store helpers
  • Message compression negotiation
  • Protobuf and JSON codecs through Network.GRPC.Common.Protobuf and Network.GRPC.Common.JSON
  • OpenTelemetry instrumentation via Network.GRPC.Client.Otel and Network.GRPC.Server.Otel

A minimal unary client call. Protobuf service types come from wireform-proto codegen or a Proto.TH.loadProto splice:

import Network.GRPC.Client
import qualified Network.GRPC.Client.StreamType.IO as IO
import Network.GRPC.Common
import 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 .~ lon

For server-side handlers, use Network.GRPC.Server.Run with handlers constructed from Network.GRPC.Server.StreamType:

import Network.GRPC.Server.Run
import 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.

ModulePurpose
Network.GRPC.ClientConnection management, withConnection, withRPC
Network.GRPC.Client.StreamType.IOUnary and streaming client handlers
Network.GRPC.ServerServer handler registration and call dispatch
Network.GRPC.Server.RunServer lifecycle and listener setup
Network.GRPC.Common.ProtobufProtobuf codec integration with wireform-proto
Network.GRPC.Common.CompressionCompression negotiation
Network.GRPC.Client.Otel / Network.GRPC.Server.OtelOpenTelemetry hooks
Network.GRPC.Util.TLSCertificate store and TLS helpers

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.