Type Aliases
The following type aliases are available globally.
-
The
ResultClosureis used by otherCodablealiases when responding with only aRequestErroris needed.The following two typealiases make use of
ResultClosure:public typealias NonCodableClosure = (@escaping ResultClosure) -> Void public typealias IdentifierNonCodableClosure<Id: Identifier> = (Id, @escaping ResultClosure) -> VoidDeclaration
Swift
public typealias ResultClosure = (RequestError?) -> Void -
The
CodableResultClosureis used by otherCodablealiases when responding with an object which conforms toCodable, or aRequestErroris 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>) -> VoidDeclaration
Swift
public typealias CodableResultClosure<O> = (O?, RequestError?) -> Void where O : Decodable, O : Encodable -
The
CodableArrayResultClosureis used by otherCodablealiases when responding with an array of objects which conform toCodable, or aRequestErroris needed.The following typealias makes use of
CodableArrayResultClosure:public typealias CodableArrayClosure<O: Codable> = (@escaping CodableArrayResultClosure<O>) -> VoidDeclaration
Swift
public typealias CodableArrayResultClosure<O> = ([O]?, RequestError?) -> Void where O : Decodable, O : Encodable -
The
IdentifierCodableArrayResultClosureis used by otherCodablealiases when responding with an array of tuples containing an identifier and aCodableobject, or aRequestError.The following typealias makes use of
IdentifierCodableArrayResultClosure:public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<[Id, O]?>) -> VoidDeclaration
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
Identifierand 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 anIdentifierorRequestError.The following typealias makes use of
IdentifierCodableResultClosure:public typealias CodableIdentifierClosure<I: Codable, Id: Identifier, O: Codable> = (I, @escaping IdentifierCodableResultClosure<Id, O>) -> VoidDeclaration
Swift
public typealias IdentifierCodableResultClosure<Id, O> = (Id?, O?, RequestError?) -> Void where Id : Identifier, O : Decodable, O : Encodable -
The
IdentifierCodableClosureis used to perform a series of actions utilising an object conforming toIdentifierand 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 aRequestErrorin the form of aCodableResultClosure.By default
Inthas conformity toIdentifier. In this example, if there has been an error you can use therespondWithcall 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
CodableClosureis 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 aRequestErrorin 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 therespondWithcall 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
CodableIdentifierClosureis 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 toIdentifieror responding with aRequestErrorin the form of aIdentifierCodableResultClosure.If no errors occurred and you have a
Userand 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 therespondWithcall 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
NonCodableClosureis used to perform a series of actions then respond with aRequestErrorin 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 therespondWithcall 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
IdentifierNonCodableClosureis used to perform a series of actions utilising an object which conforms toIdentifier, then respond with aRequestErrorin 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 therespondWithcall 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
CodableArrayClosureis used to perform a series of actions then respond with an array of objects conforming toCodableor aRequestErrorin the form of aCodableArrayResultClosure.If no errors occurred and you have an array of
Usersyou can just respond with the users by passing nil as theRequestError?value. In this example, if there has been an error you can use therespondWithcall 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
IdentifierCodableArrayClosureis 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
Usersyou can just respond with the users by passing nil as theRequestError?value. In this example, if there has been an error you can use therespondWithcall 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
SimpleCodableClosureis used to perform a series of actions, then respond with an object conforming toCodableor aRequestErrorin 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
IdentifierSimpleCodableClosureis used to perform a series of actions utilising an object which conforms toIdentifier, then respond with an object conforming toCodableor aRequestErrorin the form of aCodableResultClosure.If there has been an error you can use the
respondWithcall to respond with an appropriate error and passing nil for theUser?. In this example, if no errors occurred and you have aUseryou 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
View on GitHub
Type Aliases Reference