Type Aliases
The following type aliases are available globally.
-
The
ResultClosure
is used by otherCodable
aliases when responding with only aRequestError
is needed.The following two typealiases make use of
ResultClosure
:public typealias NonCodableClosure = (@escaping ResultClosure) -> Void public typealias IdentifierNonCodableClosure<Id: Identifier> = (Id, @escaping ResultClosure) -> Void
Declaration
Swift
public typealias ResultClosure = (RequestError?) -> Void
-
The
CodableResultClosure
is used by otherCodable
aliases when responding with an object which conforms toCodable
, or aRequestError
is needed.The following two typealiases make use of
CodableResultClosure
:public typealias IdentifierCodableClosure<Id: Identifier, I: Codable, O: Codable> = (Id, I, @escaping CodableResultClosure<O>) -> Void public typealias CodableClosure<I: Codable, O: Codable> = (I, @escaping CodableResultClosure<O>) -> Void
Declaration
Swift
public typealias CodableResultClosure<O> = (O?, RequestError?) -> Void where O : Decodable, O : Encodable
-
The
CodableArrayResultClosure
is used by otherCodable
aliases when responding with an array of objects which conform toCodable
, or aRequestError
is needed.The following typealias makes use of
CodableArrayResultClosure
:public typealias CodableArrayClosure<O: Codable> = (@escaping CodableArrayResultClosure<O>) -> Void
Declaration
Swift
public typealias CodableArrayResultClosure<O> = ([O]?, RequestError?) -> Void where O : Decodable, O : Encodable
-
The
IdentifierCodableArrayResultClosure
is used by otherCodable
aliases when responding with an array of tuples containing an identifier and aCodable
object, or aRequestError
.The following typealias makes use of
IdentifierCodableArrayResultClosure
:public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<[Id, O]?>) -> Void
Declaration
Swift
public typealias IdentifierCodableArrayResultClosure<Id, O> = ([(Id, O)]?, RequestError?) -> Void where Id : Identifier, O : Decodable, O : Encodable
-
This is used to perform a series of actions which use an object conforming to
Identifier
and an object conforming toCodable
. After which you want to respond with an object which conforms toCodable
, which is of the same type as the object passed as a parameter, or respond with anIdentifier
orRequestError
.The following typealias makes use of
IdentifierCodableResultClosure
:public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<Id, O>) -> Void
Declaration
Swift
public typealias IdentifierCodableResultClosure<Id, O> = (Id?, O?, RequestError?) -> Void where Id : Identifier, O : Decodable, O : Encodable
-
The
IdentifierCodableClosure
is used to perform a series of actions utilising an object conforming toIdentifier
and an object conforming to ‘Codable’, then respond with an object which conforms toCodable
, which is of the same type as the object passed as a parameter, or responding with aRequestError
in the form of aCodableResultClosure
.By default
Int
has conformity toIdentifier
. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error, passing nil for theUser?
. If no errors occurred and you have aUser
, you can just respond with the user, passing nil as theRequestError?
value.Usage Example:
public struct User: Codable { ... } var userStore: [Int, User] = [...] router.put("/users") { (id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in guard let oldUser = self.userStore[id] else { respondWith(nil, .notFound) return } ... respondWith(user, nil) }
Declaration
Swift
public typealias IdentifierCodableClosure<Id, I, O> = (Id, I, @escaping CodableResultClosure<O>) -> Void where Id : Identifier, I : Decodable, I : Encodable, O : Decodable, O : Encodable
-
The
CodableClosure
is used to perform a series of actions utilising an object conforming toIdentifier
, then respond with an object which conforms toCodable
, which is of the same type as the object passed as a parameter, or responding with aRequestError
in the form of aCodableResultClosure
.If no errors occurred and you have a
User
, you can just respond with the user by passing nil as theRequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error and passing nil for theUser?
.Usage Example:
public struct User: Codable { ... } router.post("/users") { (user: User, respondWith: (User?, RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith(user, nil) } else { ... respondWith(nil, .internalServerError) } }
Declaration
Swift
public typealias CodableClosure<I, O> = (I, @escaping CodableResultClosure<O>) -> Void where I : Decodable, I : Encodable, O : Decodable, O : Encodable
-
The
CodableIdentifierClosure
is used to perform a series of actions utilising an object conforming toIdentifier
, then respond with an object which conforms toCodable
, and/or an object conforming toIdentifier
or responding with aRequestError
in the form of aIdentifierCodableResultClosure
.If no errors occurred and you have a
User
and the corresponding identifier, you can just respond with the identifier and user, and pass nil as theRequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error and passing nil forInt?
and nil forUser?
.Usage Example:
public struct User: Codable { ... } router.post("/users") { (user: User, respondWith: (Int?, User?, RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith(id, user, nil) } else { ... respondWith(nil, nil, .internalServerError) } }
Declaration
Swift
public typealias CodableIdentifierClosure<I, Id, O> = (I, @escaping IdentifierCodableResultClosure<Id, O>) -> Void where I : Decodable, I : Encodable, Id : Identifier, O : Decodable, O : Encodable
-
The
NonCodableClosure
is used to perform a series of actions then respond with aRequestError
in the form of aResultClosure
.If no errors occurred you can just pass nil as the
RequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error.Usage Example:
router.delete("/users") { (respondWith: (RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith(nil) } else { respondWith(.internalServerError) ... } }
Declaration
Swift
public typealias NonCodableClosure = (@escaping ResultClosure) -> Void
-
The
IdentifierNonCodableClosure
is used to perform a series of actions utilising an object which conforms toIdentifier
, then respond with aRequestError
in the form of aResultClosure
.If no errors occurred you can just pass nil as the
RequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error.Usage Example:
router.delete("/users") { (id: Int, respondWith: (RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith(nil) } else { ... respondWith(.internalServerError) } }
Declaration
Swift
public typealias IdentifierNonCodableClosure<Id> = (Id, @escaping ResultClosure) -> Void where Id : Identifier
-
The
CodableArrayClosure
is used to perform a series of actions then respond with an array of objects conforming toCodable
or aRequestError
in the form of aCodableArrayResultClosure
.If no errors occurred and you have an array of
Users
you can just respond with the users by passing nil as theRequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error and passing nil for the[User]?
.Usage Example:
router.get("/users") { (respondWith: ([User]?, RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith(users, nil) } else { ... respondWith(nil, .internalServerError) } }
Declaration
Swift
public typealias CodableArrayClosure<O> = (@escaping CodableArrayResultClosure<O>) -> Void where O : Decodable, O : Encodable
-
The
IdentifierCodableArrayClosure
is used to perform a series of actions then respond with an array of tuples containing an identifier and a Codable object, or aRequestError
, in the form of aIdentifierCodableArrayResultClosure
.If no errors occurred and you have an array of
Users
you can just respond with the users by passing nil as theRequestError?
value. In this example, if there has been an error you can use therespondWith
call to respond with an appropriate error and passing nil for the[User]?
.Usage Example:
router.get("/users") { (respondWith: ([(Int, User)]?, RequestError?) -> Void) in if databaseConnectionIsOk { ... respondWith([(Int, User)], nil) } else { ... respondWith(nil, .internalServerError) } }
Declaration
Swift
public typealias IdentifierCodableArrayClosure<Id, O> = (@escaping IdentifierCodableArrayResultClosure<Id, O>) -> Void where Id : Identifier, O : Decodable, O : Encodable
-
The
SimpleCodableClosure
is used to perform a series of actions, then respond with an object conforming toCodable
or aRequestError
in the form of aCodableResultClosure
.Usage Example:
public struct Status: Codable { ... } router.get("/status") { (respondWith: (Status?, RequestError?) -> Void) in ... respondWith(status, nil) }
Declaration
Swift
public typealias SimpleCodableClosure<O> = (@escaping CodableResultClosure<O>) -> Void where O : Decodable, O : Encodable
-
The
IdentifierSimpleCodableClosure
is used to perform a series of actions utilising an object which conforms toIdentifier
, then respond with an object conforming toCodable
or aRequestError
in the form of aCodableResultClosure
.If there has been an error you can use the
respondWith
call to respond with an appropriate error and passing nil for theUser?
. In this example, if no errors occurred and you have aUser
you can just respond with the user by passing nil as theRequestError?
value.Usage Example:
public struct User: Codable { ... } var userStore: [Int, User] = (...) router.get("/users") { (id: Int, respondWith: (User?, RequestError?) -> Void) in guard let user = self.userStore[id] else { respondWith(nil, .notFound) return } ... respondWith(user, nil) }
Declaration
Swift
public typealias IdentifierSimpleCodableClosure<Id, O> = (Id, @escaping CodableResultClosure<O>) -> Void where Id : Identifier, O : Decodable, O : Encodable