webbridge

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 28 Imported by: 0

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 GRPCWebBridge added in v0.1.0

type GRPCWebBridge struct {
	// contains filtered or unexported fields
}

GRPCWebBridge is a gRPC bridge implementing the HTTP-based gRPC-Web protocol, as it is described in the PROTOCOL-WEB specification. It always returns a 200 OK HTTP response, writing the actual gRPC response in a Length-Prefixed message as part of the response body.

func NewGRPCWebBridge added in v0.1.0

func NewGRPCWebBridge(router routing.GRPCRouter, opts GRPCWebBridgeOpts) *GRPCWebBridge

NewGRPCWebBridge initializes a new GRPCWebBridge using the specified router and options. The router isn't optional, because no routers in grpcbridge can be constructed without some form of required args.

func (*GRPCWebBridge) ServeHTTP added in v0.1.0

func (b *GRPCWebBridge) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP implements net/http.Handler so that the bridge is used as a normal HTTP handler.

type GRPCWebBridgeOpts added in v0.1.0

type GRPCWebBridgeOpts struct {
	// Logs are discarded by default.
	Logger bridgelog.Logger

	// If not set, the default [grpcadapter.ProxyForwarder] is created with default options.
	Forwarder grpcadapter.Forwarder
}

GRPCWebBridgeOpts define all the optional settings which can be set for GRPCWebBridge and GRPCWebSocketBridge.

type GRPCWebSocketBridge added in v0.1.0

type GRPCWebSocketBridge struct {
	// contains filtered or unexported fields
}

func NewGRPCWebSocketBridge added in v0.1.0

func NewGRPCWebSocketBridge(router routing.GRPCRouter, opts GRPCWebBridgeOpts) *GRPCWebSocketBridge

func (*GRPCWebSocketBridge) ServeHTTP added in v0.1.0

func (b *GRPCWebSocketBridge) ServeHTTP(unwrappedRW http.ResponseWriter, r *http.Request)

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 optionally specified transcoder.

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, opts TranscodedHTTPBridgeOpts) *TranscodedHTTPBridge

NewTranscodedHTTPBridge initializes a new TranscodedHTTPBridge using the specified router and options. The router isn't optional, because no routers in grpcbridge can be constructed without some form of required args.

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

type TranscodedHTTPBridgeOpts struct {
	// Logs are discarded by default.
	Logger bridgelog.Logger

	// If not set, the default [transcoding.StandardTranscoder] is created with default options.
	Transcoder transcoding.HTTPTranscoder

	// If not set, the default [grpcadapter.ProxyForwarder] is created with default options.
	Forwarder grpcadapter.Forwarder
}

TranscodedHTTPBridgeOpts define all the optional settings which can be set for TranscodedHTTPBridge.

type TranscodedWebSocketBridge added in v0.1.0

type TranscodedWebSocketBridge struct {
	// contains filtered or unexported fields
}

func NewTranscodedWebSocketBridge added in v0.1.0

func NewTranscodedWebSocketBridge(router routing.HTTPRouter, opts TranscodedWebSocketBridgeOpts) *TranscodedWebSocketBridge

NewTranscodedWebSocketBridge initializes a new TranscodedWebSocketBridge using the specified router and options. The router isn't optional, because no routers in grpcbridge can be constructed without some form of required args.

func (*TranscodedWebSocketBridge) ServeHTTP added in v0.1.0

func (b *TranscodedWebSocketBridge) ServeHTTP(unwrappedRW http.ResponseWriter, r *http.Request)

type TranscodedWebSocketBridgeOpts added in v0.1.0

type TranscodedWebSocketBridgeOpts struct {
	// Logs are discarded by default.
	Logger bridgelog.Logger

	// If not set, the default [transcoding.StandardTranscoder] is created with default options.
	Transcoder transcoding.HTTPTranscoder

	// If not set, the default [grpcadapter.ProxyForwarder] is created with default options.
	Forwarder grpcadapter.Forwarder

	// MetadataParam specifies the name of the query parameter to be parsed as a map containing the metadata to be forwarded.
	// This is needed for WebSockets since there's no way to set headers on the WebSocket handshake request through the WebSocket web API.
	//
	// If not set, _metadata is used. For more info about the format, see [TranscodedWebSocketBridge.ServeHTTP].
	MetadataParam string
}

TranscodedWebSocketBridgeOpts define all the optional settings which can be set for TranscodedWebSocketBridge.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL