Vapor Documentation Beta

Protocol Middleware

public protocol Middleware

Middleware is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses. Middleware can choose to pass requests on to the next Middleware in a chain, or they can short circuit and return a custom Response if desired.

%3 Middleware Middleware Authenticator Authenticator Authenticator->Middleware CORSMiddleware CORSMiddleware CORSMiddleware->Middleware ErrorMiddleware ErrorMiddleware ErrorMiddleware->Middleware FileMiddleware FileMiddleware FileMiddleware->Middleware SessionsMiddleware SessionsMiddleware SessionsMiddleware->Middleware

Types Conforming to Middleware

Authenticator

Helper for creating authentication middleware.

CORSMiddleware

Middleware that adds support for CORS settings in request responses. For configuration of this middleware please use the CORSMiddleware.Configuration object.

ErrorMiddleware

Captures all errors and transforms them into an internal server error HTTP response.

FileMiddleware

Serves static files from a public directory.

SessionsMiddleware

Uses HTTP cookies to save and restore sessions for connecting clients.

Requirements

respond(to:​chaining​To:​)

func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>

Called with each Request that passes through this middleware.

Parameters

request Request

The incoming Request.

next Responder

Next Responder in the chain, potentially another middleware or the main router.

Returns

An asynchronous Response.