RouterMiddlewareGenerator
public class RouterMiddlewareGenerator: RouterMiddleware
Create an on the fly RouterMiddleware
from a RouterHandler
closure.
-
Initialize a
RouterMiddlewareGenerator
instanceParameter
Parameter handler: The closure that is of the typeRouterHandler
to be called to handle requestsDeclaration
Swift
public init(handler: @escaping RouterHandler)
Parameters
handler
The closure that is of the type
RouterHandler
to be called to handle requests -
Implementation of RouterMiddleware protocol. A simple wrapper around the closure that will handle the request.
Parameter
Parameter request: TheRouterRequest
object that is used to work with the incoming request.Parameter
Parameter response: TheRouterResponse
object used to send responses to the HTTP request.Parameter
Parameter next: The closure to invoke to cause the router to inspect the path in the list of paths.Declaration
Swift
public func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) throws
Parameters
request
The
RouterRequest
object that is used to work with the incoming request.response
The
RouterResponse
object used to send responses to the HTTP request.next
The closure to invoke to cause the router to inspect the path in the list of paths.