Back to Kitura

RouterMiddleware

docs/Protocols/RouterMiddleware.html

3.0.11.2 KB
Original Source

RouterMiddleware

public protocol RouterMiddleware

Defines the protocol which all Kitura compliant middleware must implement.

Middleware are class or struct based request handlers. They are often generic in nature and not tied to a specific request.

`

                handle(request:response:next:)
                `

Handle an incoming HTTP request.

Throws

Any ErrorType. If an error is thrown, processing of the request is stopped, the error handlers, if any are defined, will be invoked, and the user will get a response with a status code of 500.

Declaration

Swift

func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) throws

Parameters

| request |

The RouterRequest object used to work with the incoming HTTP request.

| | response |

The RouterResponse object used to respond to the HTTP request.

| | next |

The closure called to invoke the next handler or middleware associated with the request.

|