Protocols
The following protocols are available globally.
-
A class that conforms to
See moreBodyDecodermust be able to decode fromDatainto aCodabletype. This class can then be used to produce input objects for a Codable route.Declaration
Swift
public protocol BodyDecoder : AnyObject -
A class that conforms to
See moreBodyEncodermust be able to encode aCodabletype intoData. This class can then be used to produce output objects for a Codable route.Declaration
Swift
public protocol BodyEncoder : AnyObject -
An object that conforms to QueryParams is identified as being decodable from URLEncoded data. This can be applied to a Codable route to define the names and types of the expected query parameters, and provide type-safe access to their values. The
QueryDecoderis used to decode the URL encoded parameters into an instance of the conforming type.Usage Example:
struct Query: QueryParams { let id: Int } router.get("/user") { (query: Query, respondWith: (User?, RequestError?) -> Void) in guard let user: User = userArray[query.id] else { return respondWith(nil, .notFound) } respondWith(user, nil) }Decoding Empty Values:
When an HTML form is sent with an empty or unchecked field, the corresponding key/value pair is sent with an empty value (i.e.
&key1=&key2=). The corresponding mapping to Swift types performed byQueryDecoderis as follows:- Any Optional type (including
String?) defaults tonil - Non-optional
Stringsuccessfully decodes to"" - Non-optional
Booldecodes tofalse - All other non-optional types throw a decoding error
Declaration
Swift
public protocol QueryParams : Decodable, Encodable - Any Optional type (including
-
An identifier for an entity with a string representation.
Usage Example:
See more// Used in the Id field. public typealias IdentifierCodableClosure<Id: Identifier, I: Codable, O: Codable> = (Id, I, @escaping CodableResultClosure<O>) -> VoidDeclaration
Swift
public protocol Identifier : Decodable, Encodable -
An identifier for an operation object.
See moreDeclaration
Swift
public protocol Operation : Decodable, Encodable
View on GitHub
Protocols Reference