MiddleareType for Slimane
struct AccessLogMiddleware: MiddlewareType {
public func respond(req: Request, res: Response, next: MiddlewareChain) {
print(req.uri.path ?? "/")
next(.Chain(req, res))
}
}
Middleware Chain Result Type that enable to control middleware chain cycle
public enum MiddlewareChainResult {
case Chain(Request, Response)
case Intercept(Request, Response)
case Error(ErrorProtocol)
}
- Chain: Go to next middleware chain with current request
- Intercept: Intercept the middleware chain with current Request/Response content
- Error: Intercept the middleware chain cycle and then respond error response
Basic protocol for Slimane's Middleware
public protocol MiddlewareType: AsyncMiddleware {
func respond(req: Request, res: Response, next: MiddlewareChain)
}
import PackageDescription
let package = Package(
name: "MyMiddleware",
dependencies: [
.Package(url: "https://github.com/slimane-swift/Middleware.git", majorVersion: 0, minor: 1),
]
)
Middleware is released under the MIT license. See LICENSE for details.