Documentation ¶
Overview ¶
Package webbridge contains implementations of various handlers for bridging web-originated requests to gRPC. It allows using gRPC-only services through all kinds of interfaces supporting all the possible streaming variants.
The available functionality can be separated into two different kinds by the API format:
- Typical REST-like API implemented using classic single-request-single-response and streamed HTTP requests, streaming WebSocket connections, and Server-Sent Events, all coming with support for request path parameters, query parameters, and custom body path specification.
- Modern gRPC-Web API supporting both unary and streaming RPCs for HTTP and WebSocket requests, with WebTransport support planned, too.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TranscodedHTTPBridge ¶
type TranscodedHTTPBridge struct {
// contains filtered or unexported fields
}
TranscodedHTTPBridge is a gRPC bridge which performs transcoding between HTTP and gRPC requests/responses using the specified transcoder, which isn't an optional argument by default since a single transcoder should be used for the various available bridges for compatibility between them.
Currently, only unary RPCs are supported, and the streaming functionality of the transcoder is not used. TranscodedHTTPBridge performs transcoding not only for the request and response messages, but also for the errors and statuses returned by the router, transcoder, and gRPC connection to which the RPC is bridged. More specifically, gRPC status codes will be used to set an HTTP code according to the Closest HTTP Mapping, with the possibility to override the code by returning an error implementing interface{ HTTPStatus() int }.
Unary RPCs follow the Proto3 "all fields are optional" convention, treating completely-empty request messages as valid. This matches with gRPC-Gateway's behaviour.
func NewTranscodedHTTPBridge ¶
func NewTranscodedHTTPBridge(router routing.HTTPRouter, transcoder transcoding.HTTPTranscoder, opts TranscodedHTTPBridgeOpts) *TranscodedHTTPBridge
NewTranscodedHTTPBridge initializes a new TranscodedHTTPBridge using the specified router and transcoder.
func (*TranscodedHTTPBridge) ServeHTTP ¶
func (b *TranscodedHTTPBridge) ServeHTTP(unwrappedRW http.ResponseWriter, r *http.Request)
ServeHTTP implements net/http.Handler so that the bridge is used as a normal HTTP handler.
type TranscodedHTTPBridgeOpts ¶
TranscodedHTTPBridgeOpts define all the optional settings which can be set for TranscodedHTTPBridge.