Protocol
ContentContainer
public protocol ContentContainer
Default Implementations
decode(_:)
public func decode<D>(_ content: D.Type) throws -> D where D: Decodable
decode(_:)
public func decode<C>(_ decodable: C.Type) throws -> C where C: Content
encode(_:)
public mutating func encode<C>(_ encodable: C) throws
where C: Content
Serializes an Encodable
object to this message using specific HTTPMessageEncoder
.
try req.content.encode(user, using: JSONEncoder())
Parameters
Name | Type | Description |
---|---|---|
encodable | C |
Instance of generic |
Throws
Errors during serialization.
encode(_:as:)
public mutating func encode<E>(_ encodable: E, as contentType: HTTPMediaType) throws
where E: Encodable
Serializes an Encodable
object to this message using specific HTTPMessageEncoder
.
try req.content.encode(user, using: JSONEncoder())
Parameters
Name | Type | Description |
---|---|---|
encodable | E |
Instance of generic |
encoder | Specific |
Throws
Errors during serialization.
encode(_:as:)
public mutating func encode<C>(_ content: C, as contentType: HTTPMediaType) throws
where C: Content
Serializes a Content
object to this message using specific HTTPMessageEncoder
.
try req.content.encode(user, using: JSONEncoder())
Parameters
Name | Type | Description |
---|---|---|
content | C |
Instance of generic |
encoder | Specific |
Throws
Errors during serialization.
subscript(_:)
public subscript<D>(_ keyPath: CodingKeyRepresentable...) -> D?
where D: Decodable
Fetches a single Decodable
value at the supplied key-path from this HTTP request's query string.
Note: This is a non-throwing subscript convenience method for get(_:at:)
.
let name: String? = req.query["user", "name"]
print(name) /// String?
Parameters
Name | Type | Description |
---|---|---|
keyPath | CodingKeyRepresentable |
One or more key path components to the desired value. |
Returns
Decoded Decodable
value.
subscript(_:at:)
public subscript<D>(_ type: D.Type, at keyPath: CodingKeyRepresentable...) -> D?
where D: Decodable
Fetches a single Decodable
value at the supplied key-path from this HTTP request's query string.
Note: This is a non-throwing subscript convenience method for get(_:at:)
.
let name = req.query[String.self, at: "user", "name"]
print(name) /// String?
Parameters
Name | Type | Description |
---|---|---|
type | D.Type |
The |
keyPath | CodingKeyRepresentable |
One or more key path components to the desired value. |
Returns
Decoded Decodable
value.
subscript(_:at:)
public subscript<D>(_ type: D.Type, at keyPath: [CodingKeyRepresentable]) -> D?
where D: Decodable
Fetches a single Decodable
value at the supplied key-path from this HTTP request's query string.
Note: This is a non-throwing subscript convenience method for get(_:at:)
. This is the non-variadic version.
let name = req.query[String.self, at: "user", "name"]
print(name) /// String?
Parameters
Name | Type | Description |
---|---|---|
type | D.Type |
The |
keyPath | [CodingKeyRepresentable] |
One or more key path components to the desired value. |
Returns
Decoded Decodable
value.
get(_:at:)
public func get<D>(_ type: D.Type = D.self, at keyPath: CodingKeyRepresentable...) throws -> D
where D: Decodable
Fetches a single Decodable
value at the supplied key-path from this HTTP request's body.
let name = try req.content.get(String.self, at: "user", "name")
print(name) /// String
Parameters
Name | Type | Description |
---|---|---|
type | D.Type |
The |
keyPath | CodingKeyRepresentable |
One or more key path components to the desired value. |
Returns
Decoded Decodable
value.
get(_:at:)
public func get<D>(_ type: D.Type = D.self, at keyPath: [CodingKeyRepresentable]) throws -> D
where D: Decodable
Fetches a single Decodable
value at the supplied key-path from this HTTP request's body.
Note: This is the non-variadic version.
let name = try req.content.get(String.self, at: "user", "name")
print(name) /// String
Parameters
Name | Type | Description |
---|---|---|
type | D.Type |
The |
keyPath | [CodingKeyRepresentable] |
One or more key path components to the desired value. |
Returns
Decoded Decodable
value.
Requirements
contentType
var contentType: HTTPMediaType?
decode(_:using:)
func decode<D>(_ decodable: D.Type, using decoder: ContentDecoder) throws -> D
where D: Decodable
encode(_:using:)
mutating func encode<E>(_ encodable: E, using encoder: ContentEncoder) throws
where E: Encodable