docs/Typealiases.html
The following type aliases are available globally.
`
RequestError
`
Bridge RequestError from KituraContracts so that you only need to import Kitura to access it.
Swift
public typealias RequestError = KituraContracts.RequestError
`
HTTPStatusCode
`
Bridge HTTPStatusCode from KituraNet so that you only need to import Kitura to access it.
Swift
public typealias HTTPStatusCode = KituraNet.HTTPStatusCode
ServerOptions
`
ServerOptions
`
Bridge ServerOptions from KituraNet so that you only need to import Kitura to access it.
ServerOptions allows customization of default connection policies, including:
requestSizeLimit: Defines the maximum size of an incoming request body, in bytes. If requests are received that are larger than this limit, they will be rejected and the connection will be closed. A value of nil means no limit.connectionLimit: Defines the maximum number of concurrent connections that a server should accept. Clients attempting to connect when this limit has been reached will be rejected. A value of nil means no limit.The server can optionally respond to the client with a message in either of these cases. This message can be customized by defining requestSizeResponseGenerator and connectionResponseGenerator.
Example usage:
let port = 8080
let router = Router()
let connectionResponse: (Int, String) -> (HTTPStatusCode, String)? = { (limit, client) in
Log.debug("Rejecting request from \(client): Connection limit \(limit) reached")
return (.serviceUnavailable, "Service busy - please try again later.\r\n")
}
let serverOptions = ServerOptions(requestSizeLimit: 1000, connectionLimit: 10, connectionResponseGenerator: connectionResponse)
Kitura.addHTTPServer(onPort: port, with: router, options: serverOptions)
Swift
public typealias ServerOptions = KituraNet.ServerOptions
`
RouterHandler
`
The definition of the closure type that is used by the Router class when routing HTTP requests to closure.
Swift
public typealias RouterHandler = (RouterRequest, RouterResponse, @escaping () -> Void) throws -> Void
| 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.
|
`
RouterParameterHandler
`
A type alias declaration to describe a handler for named parameters when using Router.parameter(...). The example below shows two ways to use it, both as a function named handler to handle the “id” parameter and as a closure to handle the “name” parameter.
let router = Router()
func handler(request: RouterRequest, response: RouterResponse, param: String, next: @escaping () -> Void) throws -> Void {
//Code to handle id parameter here
next()
}
router.parameter("id", handler: handler)
router.parameter("name") { request, response, param, next in
//Code to handle name parameter here
next()
}
router.get("/item/:id") { request, response, next in
//This will be reached after the id parameter is handled by `handler`
}
router.get("/user/:name") { request, response, next in
//This will be reached after the name parameter is handled by the closure above
}
Swift
public typealias RouterParameterHandler = (RouterRequest, RouterResponse, String, @escaping () -> Void) throws -> Void
| request |
The RouterRequest object used to work with the incoming HTTP request.
|
| response |
The RouterResponse object used to respond to the HTTP request.
|
| param |
The named parameter to be handled.
|
| next |
The closure called to invoke the next handler or middleware associated with the request.
|
RouterResponse
`
LifecycleHandler
`
Type alias for “Before flush” (i.e. before headers and body are written) lifecycle handler.
Swift
public typealias LifecycleHandler = () -> Void
`
WrittenDataFilter
`
Type alias for written data filter, i.e. pre-write lifecycle handler.
Swift
public typealias WrittenDataFilter = (Data) -> Data