Router
public class Router
Router
provides the external interface for routing requests to
the appropriate code to handle them. This includes:
- Routing requests to closures of type
RouterHandler
- Routing requests to the handle function of classes that implement the
RouterMiddleware
protocol. - Routing requests to a
TemplateEngine
to generate the appropriate output. - Serving the landing page when someone makes an HTTP request with a path of slash (/).
-
The root directory where template files should be placed in order to be automatically handed over to an appropriate templating engine for content generation. The directory should sit at the same level as the project’s
Sources
directory. Defaults to./Views/
.Usage Example:
The example below changes the directory where template files should be placed to be
./myViews/
let router = Router() router.viewsPath = "./myViews/"
Declaration
Swift
public var viewsPath = "./Views/"
-
Returns the current in-memory representation of Codable routes as a Swagger document in JSON format, or nil if the document cannot be generated.
Declaration
Swift
public var swaggerJSON: String?
-
Initialize a
Router
instance.Usage Example:
let router = Router()
Using
mergeParameters
:When initialising a
Router
,mergeParameters
allows you to control whether the router will be able to access parameters matched in its parent router. For instance, in the example below ifmergeParameters
is set totrue
,GET /Hello/Alex
will returnHello Alex
, but if set tofalse
thegreeting
parameter will not be accessible and it will return justAlex
.let router = Router() let userRouter = Router(mergeParameters: true) router.get("/:greeting") { request, response, _ in let greeting = request.parameters["greeting"] ?? "" try response.send("\(greeting)").end() } userRouter.get("/:user") { request, response, _ in let user = request.parameters["user"] ?? "" let greeting = request.parameters["greeting"] ?? "" try response.send("\(greeting) \(user)").end() } router.all("/:greeting", middleware: userRouter)
Declaration
Swift
public init(mergeParameters: Bool = false)
Parameters
mergeParameters
Optional parameter to specify if the router should be able to access parameters from its parent router. Defaults to
false
if not specified.
-
Register a template engine to a given router instance. A template engine allows rendering of documents using static templates.
By default the templating engine will handle files in the
./Views
directory that match the file extension it supports. You can change this default location using theviewsPath
property.Usage Example:
let router = Router() router.add(templateEngine: MyTemplateEngine()) router.add(templateEngine: MyOtherTemplateEngine(), forFileExtensions: ["html"], useDefaultFileExtension: false)
If multiple different template engines are registered for the same extension, the template engine that is registered last will be the one that attempts to render all template files with the chosen extension.
Declaration
Swift
public func add(templateEngine: TemplateEngine, forFileExtensions fileExtensions: [String] = [], useDefaultFileExtension: Bool = true)
Parameters
templateEngine
The templating engine to register.
forFileExtensions
The extensions of the files to apply the template engine on.
useDefaultFileExtension
The flag to specify if the default file extension of the template engine should be used. Defaults to
true
if not specified. -
Sets the default templating engine to be used when the extension of a file in the
viewsPath
doesn’t match the extension of one of the registered templating engines.Usage Example:
let router = Router() router.setDefault(templateEngine: MyTemplateEngine())
If the template engine doesn’t provide a default extension you can provide one using
add(templateEngine:forFileExtensions:useDefaultFileExtension:)
. If a router instance doesn’t have a template engine registered that can render the given template file aNo template engine defined for extension
TemplatingError
is thrown.Declaration
Swift
public func setDefault(templateEngine: TemplateEngine?)
Parameters
templateEngine
The templating engine to set as default.
-
Set up a
sub router
to handle requests. Chaining a route handler onto another router can make it easier to build a server that serves a large set of paths. Each sub router handles all of the path mappings below its parent’s route path.Usage Example:
The example below shows how the route `/parent/child’ can be defined using a sub router.
let router = Router() let parent = router.route("/parent") parent.get("/child") { request, response, next in // If allowPartialMatch was set to false, this would not be called. }
Declaration
Swift
public func route(_ route: String, mergeParameters: Bool = false, allowPartialMatch: Bool = true) -> Router
Parameters
route
The path to bind the sub router to.
mergeParameters
Specify if this router should have access to path parameters matched in its parent router. Defaults to
false
if not specified.allowPartialMatch
Specify if the sub router allows a match when additional paths are added. In the example above, the
GET
request to/parent/child
would only succeed ifallowPartialMatch
is set totrue
. Defaults totrue
if not specified.Return Value
The sub router which has been created.
-
Set up handlers for a named request parameter. This can make it easier to handle multiple routes requiring the same parameter which needs to be handled in a certain way.
Usage Example:
let router = Router() router.parameter("id") { request, response, param, next in if let _ = Int(param) { // Id is an integer, continue next() } else { // Id is not an integer, error try response.status(.badRequest).send("ID is not an integer").end() } } router.get("/item/:id") { request, response, _ in // This will only be reached if the id parameter is an integer } router.get("/user/:id") { request, response, _ in // This will only be reached if the id parameter is an integer }
Declaration
Swift
public func parameter(_ name: String, handler: RouterParameterHandler...) -> Router
Parameters
name
The single parameter name to be handled.
handler
The comma delimited set of
RouterParameterHandler
instances that will be invoked when request parses a parameter with the specified name.Return Value
The current router instance.
-
Set up handlers for a number of named request parameters. This can make it easier to handle multiple routes requiring similar parameters which need to be handled in a certain way.
Usage Example:
let router = Router() router.parameter(["id", "num"]) { request, response, param, next in if let _ = Int(param) { // Parameter is an integer, continue next() } else { // Parameter is not an integer, error try response.status(.badRequest).send("\(param) is not an integer").end() } } router.get("/item/:id/:num") { request, response, _ in // This will only be reached if the id and num parameters are integers. }
Declaration
Swift
public func parameter(_ names: [String], handler: RouterParameterHandler...) -> Router
Parameters
names
The array of parameter names to be handled.
handler
The comma delimited set of
RouterParameterHandler
instances that will be invoked when request parses a parameter with the specified name.Return Value
The current router instance.
-
Set up handlers for a number of named request parameters. This can make it easier to handle multiple routes requiring similar parameters which need to be handled in a certain way.
Usage Example:
let router = Router() func handleInt(request: RouterRequest, response: RouterResponse, param: String, next: @escaping () -> Void) throws -> Void { if let _ = Int(param) { // Parameter is an integer, continue } else { // Parameter is not an integer, error try response.status(.badRequest).send("\(param) is not an integer").end() } next() } func handleItem(request: RouterRequest, response: RouterResponse, param: String, next: @escaping () -> Void) throws -> Void { let itemId = Int(param) //This will only be reached if id is an integer ... } router.parameter(["id"], handlers: [handleInt, handleItem]) router.get("/item/:id/") { request, response, _ in ... }
Declaration
Swift
public func parameter(_ names: [String], handlers: [RouterParameterHandler]) -> Router
Parameters
names
The array of parameter names to be handled.
handlers
The array of
RouterParameterHandler
instances that will be invoked when request parses a parameter with the specified name. The handlers are executed in the order they are supplied.Return Value
The current router instance.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an optionalUser
, whereUser
conforms to Codable.router.get("/user") { (session: MySession, respondWith: (User?, RequestError?) -> Void) in guard let user: User = session.user else { return respondWith(nil, .notFound) } respondWith(user, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, O: Codable>( _ route: String, handler: @escaping (T, CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and returns a single Codable object or a RequestError.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
and a handler which responds with an array of Codable objects or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an optionalUser
array, whereUser
conforms to Codable.router.get("/user") { (session: MySession, respondWith: ([User]?, RequestError?) -> Void) in guard let user: [User] = session.user else { return respondWith(nil, .notFound) } respondWith([user], nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, respondWith: ([User]?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, O: Codable>( _ route: String, handler: @escaping (T, CodableArrayResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and returns an array of Codable objects or a RequestError.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, anIdentifier
and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.router.get("/user") { (session: MySession, id: Int, respondWith: (User?, RequestError?) -> Void) in guard let user: User = session.user[id] else { return respondWith(nil, .notFound) } respondWith(user, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, id: Int, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, Id: Identifier, O: Codable>( _ route: String, handler: @escaping (T, Id, CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and an Identifier, and returns a single of Codable object or a RequestError.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
and a handler which responds with an array of (Identifier
, Codable) tuples or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [(Int, User)] dictionary, whereUser
conforms to Codable.router.get("/user") { (session: MySession, respondWith: ([(Int, User)]?, RequestError?) -> Void) in guard let users: [(Int, User)] = session.users else { return respondWith(nil, .notFound) } respondWith(users, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, id: Int, respondWith: ([(Int, User)]?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, Id: Identifier, O: Codable>( _ route: String, handler: @escaping (T, IdentifierCodableArrayResultClosure<Id, O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance, and returns an array of (Identifier, Codable) tuples or a RequestError.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, the parsed query parameters, and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.struct Query: QueryParams { let id: Int } router.get("/user") { (session: MySession, query: Query, respondWith: (User?, RequestError?) -> Void) in guard let user: User = session.user[query.id] else { return respondWith(nil, .notFound) } respondWith(user, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, query: Query, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, Q: QueryParams, O: Codable>( _ route: String, handler: @escaping (T, Q, @escaping CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and a QueryParams instance, and returns a single of Codable object or a RequestError.
-
Sets up a closure that will be invoked when a GET request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, the parsed query parameters, and a handler which responds with an array of Codable objects or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: [User]] dictionary, whereUser
conforms to Codable.struct Query: QueryParams { let id: Int } router.get("/user") { (session: MySession, query: Query, respondWith: ([User]?, RequestError?) -> Void) in guard let user: [User] = session.user[query.id] else { return respondWith(nil, .notFound) } respondWith(user, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.get("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, query: Query, respondWith: ([User]?, RequestError?) -> Void) in
Declaration
Swift
public func get<T: TypeSafeMiddleware, Q: QueryParams, O: Codable>( _ route: String, handler: @escaping (T, Q, @escaping CodableArrayResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and a QueryParams instance, and returns an array of Codable objects or a RequestError.
-
Sets up a closure that will be invoked when a DELETE request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
and a handler which responds with nil on success, or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an optionalUser
, whereUser
conforms to Codable.router.delete("/user") { (session: MySession, respondWith: (RequestError?) -> Void) in session.user: User? = nil respondWith(nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.delete("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, respondWith: (RequestError?) -> Void) in
Declaration
Swift
public func delete<T: TypeSafeMiddleware>( _ route: String, handler: @escaping (T, ResultClosure) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware and returns a RequestError or nil on success.
-
Sets up a closure that will be invoked when a DELETE request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, anIdentifier
and a handler which responds with nil on success, or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.router.delete("/user") { (session: MySession, id: Int, respondWith: (RequestError?) -> Void) in session.user[id] = nil respondWith(nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.delete("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, id: Int, respondWith: (RequestError?) -> Void) in
Declaration
Swift
public func delete<T: TypeSafeMiddleware, Id: Identifier>( _ route: String, handler: @escaping (T, Id, ResultClosure) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware and Identifier, and returns nil on success, or a
RequestError
. -
Sets up a closure that will be invoked when a DELETE request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, the parsed query parameters, and a handler which responds with nil on success, or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.struct Query: QueryParams { let id: Int } router.delete("/user") { (session: MySession, query: Query, respondWith: (RequestError?) -> Void) in session.user[query.id] = nil respondWith(nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.delete("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, query: Query, respondWith: (RequestError?) -> Void) in
Declaration
Swift
public func delete<T: TypeSafeMiddleware, Q: QueryParams>( _ route: String, handler: @escaping (T, Q, @escaping ResultClosure) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware and Identifier, and returns nil on success, or a
RequestError
. -
Sets up a closure that will be invoked when a POST request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, a Codable object and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an optionalUser
, whereUser
conforms to Codable.router.post("/user") { (session: MySession, user: User, respondWith: (User?, RequestError?) -> Void) in if session.user == nil { return respondWith(nil, .badRequest) } else { session.user = user respondWith(user, nil) } }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.post("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, user: User, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func post<T: TypeSafeMiddleware, I: Codable, O: Codable>( _ route: String, handler: @escaping (T, I, CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and a Codable object, and returns a Codable object or a RequestError.
-
Sets up a closure that will be invoked when a POST request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, a Codable object and a handler which responds with anIdentifier
and a Codable object, or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.router.post("/user") { (session: MySession, user: User, respondWith: (Int?, User?, RequestError?) -> Void) in let newId = session.users.count + 1 session.user[newId] = user respondWith(newId, user, nil) } }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.post("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, user: User, respondWith: (Int?, User?, RequestError?) -> Void) in
Declaration
Swift
public func post<T: TypeSafeMiddleware, I: Codable, Id: Identifier, O: Codable>( _ route: String, handler: @escaping (T, I, IdentifierCodableResultClosure<Id, O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance and a Codable object, and returns an Identifier and a Codable object or a RequestError.
-
Sets up a closure that will be invoked when a PUT request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, anIdentifier
, a Codable object and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.router.post("/user") { (session: MySession, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in session.user[id] = user respondWith(user, nil) }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.put("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func put<T: TypeSafeMiddleware, Id: Identifier, I: Codable, O: Codable>( _ route: String, handler: @escaping (T, Id, I, CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance, an Identifier and a Codable object, and returns a Codable object or a RequestError.
-
Sets up a closure that will be invoked when a PATCH request to the provided route is received by the server. The closure accepts a successfully executed instance of
TypeSafeMiddleware
, anIdentifier
, a Codable object and a handler which responds with a single Codable object or aRequestError
. The handler contains the developer’s logic, which determines the server’s response.Usage Example:
In this example,
MySession
is a struct that conforms to theTypeSafeMiddleware
protocol and specifies an [Int: User] dictionary, whereUser
conforms to Codable.router.patch("/user") { (session: MySession, id: Int, inputUser: User, respondWith: (User?, RequestError?) -> Void) in guard let user: User = session.user[id] else { return respondWith(nil, .notFound) } user.id = inputUser.id ?? user.id user.name = inputUser.name ?? user.name respondWith(user, nil) } }
Multiple Middleware:
The closure can process up to three
TypeSafeMiddleware
objects by defining them in the handler:router.patch("/user") { (middle1: Middle1, middle2: Middle2, middle3: Middle3, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
Declaration
Swift
public func patch<T: TypeSafeMiddleware, Id: Identifier, I: Codable, O: Codable>( _ route: String, handler: @escaping (T, Id, I, CodableResultClosure<O>) -> Void )
Parameters
route
A String specifying the URL path that will invoke the handler.
handler
A closure that receives a TypeSafeMiddleware instance, an Identifier and a Codable object, and returns a Codable object or a RequestError.
-
Setup a CodableArrayClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//User is a struct object that conforms to Codable router.get("/users") { (respondWith: ([User]?, RequestError?) -> Void) in ... respondWith(users, nil) }
Declaration
Swift
public func get<O: Codable>(_ route: String, handler: @escaping CodableArrayClosure<O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A CodableArrayClosure that gets invoked when a request comes to the server.
-
Setup a SimpleCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//Status is a struct object that conforms to Codable router.get("/status") { (respondWith: (Status?, RequestError?) -> Void) in ... respondWith(status, nil) }
Declaration
Swift
public func get<O: Codable>(_ route: String, handler: @escaping SimpleCodableClosure<O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A SimpleCodableClosure that gets invoked when a request comes to the server.
-
Setup a IdentifierSimpleCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//User is a struct object that conforms to Codable router.get("/users") { (id: Int, respondWith: (User?, RequestError?) -> Void) in ... respondWith(user, nil) }
Declaration
Swift
public func get<Id: Identifier, O: Codable>(_ route: String, handler: @escaping IdentifierSimpleCodableClosure<Id, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
An IdentifierSimpleCodableClosure that gets invoked when a request comes to the server.
-
Setup a IdentifierCodableArrayClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//User is a struct object that conforms to Codable router.get("/users") { (respondWith: ([(Int, User)]?, RequestError?) -> Void) in ... respondWith([(Int, User)], nil) }
Declaration
Swift
public func get<Id: Identifier, O: Codable>(_ route: String, handler: @escaping IdentifierCodableArrayClosure<Id, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A IdentifierCodableArrayClosure that gets invoked when a request comes to the server.
-
Setup a (QueryParams, CodableArrayResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters // User is a struct object that conforms to Codable router.get("/query") { (query: MyQuery, respondWith: ([User]?, RequestError?) -> Void) in ... respondWith(users, nil) }
Declaration
Swift
public func get<Q: QueryParams, O: Codable>(_ route: String, handler: @escaping (Q, @escaping CodableArrayResultClosure<O>) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams, CodableArrayResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a (QueryParams, CodableResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters // User is a struct object that conforms to Codable router.get("/query") { (query: MyQuery, respondWith: (User?, RequestError?) -> Void) in ... respondWith(user, nil) }
Declaration
Swift
public func get<Q: QueryParams, O: Codable>(_ route: String, handler: @escaping (Q, @escaping CodableResultClosure<O>) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams, CodableResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a (QueryParams?, CodableArrayResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters // User is a struct object that conforms to Codable router.get("/query") { (query: MyQuery?, respondWith: ([User]?, RequestError?) -> Void) in ... respondWith(users, nil) }
Declaration
Swift
public func get<Q: QueryParams, O: Codable>(_ route: String, handler: @escaping (Q?, @escaping CodableArrayResultClosure<O>) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams?, CodableArrayResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a (QueryParams?, CodableResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters // User is a struct object that conforms to Codable router.get("/query") { (query: MyQuery?, respondWith: (User?, RequestError?) -> Void) in ... respondWith(user, nil) }
Declaration
Swift
public func get<Q: QueryParams, O: Codable>(_ route: String, handler: @escaping (Q?, @escaping CodableResultClosure<O>) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams?, CodableResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a NonCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
router.delete("/users") { (respondWith: (RequestError?) -> Void) in ... respondWith(nil) }
Declaration
Swift
public func delete(_ route: String, handler: @escaping NonCodableClosure)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
An NonCodableClosure that gets invoked when a request comes to the server.
-
Setup a IdentifierNonCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
router.delete("/users") { (id: Int, respondWith: (RequestError?) -> Void) in ... respondWith(nil) }
Declaration
Swift
public func delete<Id: Identifier>(_ route: String, handler: @escaping IdentifierNonCodableClosure<Id>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
An IdentifierNonCodableClosure that gets invoked when a request comes to the server.
-
Setup a (QueryParams, ResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters router.delete("/query") { (query: MyQuery, respondWith: (RequestError?) -> Void) in ... respondWith(nil) }
Declaration
Swift
public func delete<Q: QueryParams>(_ route: String, handler: @escaping (Q, @escaping ResultClosure) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams, ResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a (QueryParams?, ResultClosure) -> Void on the provided route which will be invoked when a request comes to the server.
Usage Example:
// MyQuery is a codable struct defining the supported query parameters router.delete("/query") { (query: MyQuery?, respondWith: (RequestError?) -> Void) in ... respondWith(nil) }
Declaration
Swift
public func delete<Q: QueryParams>(_ route: String, handler: @escaping (Q?, @escaping ResultClosure) -> Void)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A (QueryParams?, ResultClosure) -> Void that gets invoked when a request comes to the server.
-
Setup a CodableClosure on the provided route which will be invoked when a POST request comes to the server. In this scenario, the ID (i.e. unique identifier) is a field in the Codable instance.
Usage Example:
//User is a struct object that conforms to Codable router.post("/users") { (user: User, respondWith: (User?, RequestError?) -> Void) in ... respondWith(user, nil) }
Declaration
Swift
public func post<I: Codable, O: Codable>(_ route: String, handler: @escaping CodableClosure<I, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A Codable closure that gets invoked when a request comes to the server.
-
Setup a CodableIdentifierClosure on the provided route which will be invoked when a POST request comes to the server. In this scenario, the ID (i.e. unique identifier) for the Codable instance is a separate field (which is sent back to the client in the location HTTP header).
Usage Example:
//User is a struct object that conforms to Codable router.post("/users") { (user: User, respondWith: (Int?, User?, RequestError?) -> Void) in ... respondWith(id, user, nil) }
Declaration
Swift
public func post<I: Codable, Id: Identifier, O: Codable>(_ route: String, handler: @escaping CodableIdentifierClosure<I, Id, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
A Codable closure that gets invoked when a request comes to the server.
-
Setup a IdentifierCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//User is a struct object that conforms to Codable router.put("/users") { (id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in ... respondWith(user, nil) }
Declaration
Swift
public func put<Id: Identifier, I: Codable, O: Codable>(_ route: String, handler: @escaping IdentifierCodableClosure<Id, I, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
An Identifier Codable closure that gets invoked when a request comes to the server.
-
Setup a IdentifierCodableClosure on the provided route which will be invoked when a request comes to the server.
Usage Example:
//User is a struct object that conforms to Codable //OptionalUser is a struct object that conforms to Codable where all properties are optional router.patch("/users") { (id: Int, patchUser: OptionalUser, respondWith: (User?, RequestError?) -> Void) -> Void in ... respondWith(user, nil) }
Declaration
Swift
public func patch<Id: Identifier, I: Codable, O: Codable>(_ route: String, handler: @escaping IdentifierCodableClosure<Id, I, O>)
Parameters
route
A String specifying the pattern that needs to be matched, in order for the handler to be invoked.
handler
An Identifier Codable closure that gets invoked when a request comes to the server.
-
Handle an HTTP request as a middleware. Used internally in
Router
to allow for sub routing.Throws
AnyErrorType
. 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
public 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.
-
Handle new incoming requests to the server.
Declaration
Swift
public func handle(request: ServerRequest, response: ServerResponse)
Parameters
request
The
ServerRequest
object used to work with the incoming HTTP request at the Kitura-net API level.response
The
ServerResponse
object used to send responses to the HTTP request at the Kitura-net API level.
-
Setup error handling that will cause a set of one or more closures of the type
RouterHandler
to be invoked when an error occurs.Declaration
Swift
public func error(_ handler: RouterHandler...) -> Router
Parameters
handler
A comma delimited set of
RouterHandler
that will be invoked if an error ocurrs. -
Setup error handling that will cause an array of one or more closures of the type
RouterHandler
to be invoked when an error occurs.Declaration
Swift
public func error(_ handler: [RouterHandler]) -> Router
Parameters
handler
An array of
RouterHandler
that will be invoked if an error ocurrs. -
Setup error handling that will cause a set of one or more
RouterMiddleware
to be invoked when an error occurs.Declaration
Swift
public func error(_ middleware: RouterMiddleware...) -> Router
Parameters
middleware
A comma delimited set of
RouterMiddleware
that will be invoked if an error ocurrs. -
Setup error handling that will cause an array of one or more
RouterMiddleware
to be invoked when an error occurs.Declaration
Swift
public func error(_ middleware: [RouterMiddleware]) -> Router
Parameters
middleware
An array of
RouterMiddleware
that will be invoked if an error ocurrs.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when any request comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func all(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when any request comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when any request comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func all(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when any request comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when any request comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func all(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when any request comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when any request comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func all(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when any request comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP GET requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func get(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP GET requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP GET requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func get(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP GET requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP GET requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func get(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP GET requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP GET requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func get(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP GET requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP HEAD requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func head(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP HEAD requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP HEAD requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func head(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP HEAD requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP HEAD requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func head(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP HEAD requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP HEAD requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func head(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP HEAD requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP POST requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func post(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP POST requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP POST requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func post(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP POST requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP POST requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func post(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP POST requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP POST requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func post(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP POST requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP PUT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func put(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP PUT requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP PUT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func put(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP PUT requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP PUT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func put(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP PUT requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP PUT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func put(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP PUT requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP DELETE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func delete(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP DELETE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP DELETE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func delete(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP DELETE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP DELETE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func delete(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP DELETE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP DELETE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func delete(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP DELETE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP OPTIONS requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func options(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP OPTIONS requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP OPTIONS requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func options(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP OPTIONS requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP OPTIONS requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func options(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP OPTIONS requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP OPTIONS requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func options(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP OPTIONS requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP TRACE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func trace(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP TRACE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP TRACE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func trace(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP TRACE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP TRACE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func trace(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP TRACE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP TRACE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func trace(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP TRACE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP COPY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func copy(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP COPY requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP COPY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func copy(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP COPY requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP COPY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func copy(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP COPY requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP COPY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func copy(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP COPY requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP LOCK requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func lock(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP LOCK requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP LOCK requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func lock(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP LOCK requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP LOCK requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func lock(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP LOCK requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP LOCK requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func lock(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP LOCK requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP MKCOL requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mkCol(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP MKCOL requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP MKCOL requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mkCol(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP MKCOL requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP MKCOL requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mkCol(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP MKCOL requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP MKCOL requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mkCol(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP MKCOL requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP MOVE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func move(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP MOVE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP MOVE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func move(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP MOVE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP MOVE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func move(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP MOVE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP MOVE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func move(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP MOVE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP PURGE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func purge(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP PURGE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP PURGE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func purge(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP PURGE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP PURGE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func purge(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP PURGE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP PURGE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func purge(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP PURGE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP PROPFIND requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func propFind(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP PROPFIND requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP PROPFIND requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func propFind(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP PROPFIND requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP PROPFIND requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func propFind(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP PROPFIND requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP PROPFIND requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func propFind(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP PROPFIND requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP PROPPATCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func propPatch(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP PROPPATCH requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP PROPPATCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func propPatch(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP PROPPATCH requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP PROPPATCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func propPatch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP PROPPATCH requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP PROPPATCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func propPatch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP PROPPATCH requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP UNLOCK requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func unlock(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP UNLOCK requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP UNLOCK requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func unlock(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP UNLOCK requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP UNLOCK requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func unlock(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP UNLOCK requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP UNLOCK requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func unlock(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP UNLOCK requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP REPORT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func report(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP REPORT requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP REPORT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func report(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP REPORT requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP REPORT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func report(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP REPORT requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP REPORT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func report(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP REPORT requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP MKACTIVITY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mkActivity(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP MKACTIVITY requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP MKACTIVITY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mkActivity(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP MKACTIVITY requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP MKACTIVITY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mkActivity(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP MKACTIVITY requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP MKACTIVITY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mkActivity(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP MKACTIVITY requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP CHECKOUT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func checkout(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP CHECKOUT requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP CHECKOUT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func checkout(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP CHECKOUT requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP CHECKOUT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func checkout(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP CHECKOUT requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP CHECKOUT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func checkout(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP CHECKOUT requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP MERGE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func merge(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP MERGE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP MERGE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func merge(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP MERGE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP MERGE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func merge(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP MERGE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP MERGE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func merge(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP MERGE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP MSEARCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mSearch(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP MSEARCH requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP MSEARCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func mSearch(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP MSEARCH requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP MSEARCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mSearch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP MSEARCH requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP MSEARCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func mSearch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP MSEARCH requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP NOTIFY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func notify(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP NOTIFY requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP NOTIFY requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func notify(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP NOTIFY requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP NOTIFY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func notify(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP NOTIFY requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP NOTIFY requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func notify(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP NOTIFY requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP SUBSCRIBE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func subscribe(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP SUBSCRIBE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP SUBSCRIBE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func subscribe(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP SUBSCRIBE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP SUBSCRIBE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func subscribe(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP SUBSCRIBE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP SUBSCRIBE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func subscribe(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP SUBSCRIBE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func unsubscribe(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func unsubscribe(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func unsubscribe(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func unsubscribe(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP UNSUBSCRIBE requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP PATCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func patch(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP PATCH requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP PATCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func patch(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP PATCH requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP PATCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func patch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP PATCH requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP PATCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func patch(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP PATCH requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP SEARCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func search(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP SEARCH requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP SEARCH requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func search(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP SEARCH requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP SEARCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func search(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP SEARCH requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP SEARCH requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func search(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP SEARCH requests comes to the server.
-
Setup a set of one or more closures of the type
RouterHandler
that will be invoked when HTTP CONNECT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func connect(_ path: String?=nil, handler: RouterHandler...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
A comma delimited set of
RouterHandler
s that will be invoked when HTTP CONNECT requests comes to the server. -
Setup an array of one or more closures of the type
RouterHandler
that will be invoked when HTTP CONNECT requests comes to the server. If a path pattern is specified, the handlers will only be invoked if the pattern is matched.Declaration
Swift
public func connect(_ path: String?=nil, handler: [RouterHandler]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the handlers to be invoked.
handler
The array of
RouterHandler
s that will be invoked when HTTP CONNECT requests comes to the server. -
Setup a set of one or more
RouterMiddleware
that will be invoked when HTTP CONNECT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func connect(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: RouterMiddleware...) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
A comma delimited set of
RouterMiddleware
that will be invoked when HTTP CONNECT requests comes to the server. -
Setup an array of one or more
RouterMiddleware
that will be invoked when HTTP CONNECT requests comes to the server. If a path pattern is specified, theRouterMiddleware
will only be invoked if the pattern is matched.Declaration
Swift
public func connect(_ path: String?=nil, allowPartialMatch: Bool = true, middleware: [RouterMiddleware]) -> Router
Parameters
path
An optional String specifying the pattern that needs to be matched, in order for the
RouterMiddleware
to be invoked.allowPartialMatch
A Bool that indicates whether or not a partial match of the path by the pattern is sufficient.
handler
The array of
RouterMiddleware
that will be invoked when HTTP CONNECT requests comes to the server.
-
Register GET route
Declaration
Swift
public func registerGetRoute<O: Codable>(route: String, id: Bool, outputtype: O.Type)
Parameters
route
The route to register.
id
Boolean to indicate if id is used.
outputtype
The output object type.
-
Register DELETE route
Declaration
Swift
public func registerDeleteRoute(route: String, id: Bool)
Parameters
route
The route to register.
id
Boolean to indicate if id is used.
-
Register POST route that is handled by a CodableIdentifierClosure.
Declaration
Swift
public func registerPostRoute<I: Codable, O: Codable>(route: String, id: Bool, inputtype: I.Type, outputtype: O.Type)
Parameters
route
The route to register.
id
Boolean to indicate if id is used.
inputtype
The input object type.
outputtype
The output object type.
-
Register PUT route that is handled by a IdentifierCodableClosure.
Declaration
Swift
public func registerPutRoute<I: Codable, O: Codable>(route: String, id: Bool, inputtype: I.Type, outputtype: O.Type)
Parameters
route
The route to register.
id
Boolean to indicate if id is used.
inputtype
The input object type.
outputtype
The output object type.
-
Register PATCH route that is handled by an IdentifierCodableClosure.
Declaration
Swift
public func registerPatchRoute<I: Codable, O: Codable>(route: String, id: Bool, inputtype: I.Type, outputtype: O.Type)
Parameters
route
The route to register.
id
Boolean to indicate if id is used.
inputtype
The input object type.
outputtype
The output object type.