GRPCMiddleware
public class GRPCMiddleware : Middleware
A GRPCMiddleware
instance can be integrated as a middleware into the Vapor application like this:
app.middleware.use(GRPCMiddleware())
This middleware checks the content-type of incoming requests and in handles them in case of a gRPC request or forwards them to the next middleware.
It implements Vapor’s Moiddleware
protocol which requires it to implement a respond
function.
-
Initializes a
GRPCMiddleware
using theGRPCServices
passed as an argument.Declaration
Swift
public init(services: [GRPCService] = [])
Parameters
services
GRPCService
instances that should be included for routing.
-
Adds
GRPCService
instance to theservices
dictionary.Declaration
Swift
public func addService(_ service: GRPCService)
Parameters
service
GRPCService
instance that should be used by the middleware. -
Handles to incoming Vapor
Request
s and responds with anEventLoopFuture
of a VaporResponse
.This method starts out by checking if the incoming request can be handeled by this middleware or should be forwarded to the next responder. It can handle the incoming request if its content-type is
application/grpc
and thegetCallHandler
method returns a call handler. If this middleware can handle the request it returns theresponse
of the call handler which is of typeEventLoopFuture<Response>
.Declaration
Swift
public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>
Parameters
request
Incoming Vapor
Request
instance that should be handled.next
Responder
instance that either is the next middleware or the Vapor router. This one is used if the incoming request can’t be handled by this middleware.Return Value
An
EventLoopFuture
of a VaporResponse
that will be sent to the client by the Vapor stack.