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 respondfunction.

Initializers

  • Initializes a GRPCMiddleware using the GRPCServices passed as an argument.

    Declaration

    Swift

    public init(services: [GRPCService] = [])

    Parameters

    services

    GRPCService instances that should be included for routing.

Public Methods

  • Adds GRPCService instance to the services dictionary.

    Declaration

    Swift

    public func addService(_ service: GRPCService)

    Parameters

    service

    GRPCService instance that should be used by the middleware.

  • Handles to incoming Vapor Requests and responds with an EventLoopFuture of a Vapor Response.

    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 the getCallHandler method returns a call handler. If this middleware can handle the request it returns the response 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

    Responderinstance 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 Vapor Response that will be sent to the client by the Vapor stack.