Protocol
Content
Convertible to / from content in an HTTP message.
protocol Content : Decodable, Encodable, RequestDecodable, ResponseEncodable
Overview
Conformance to this protocol consists of:
CodableRequestDecodableResponseEncodable
If adding conformance in an extension, you must ensure the type already conforms to Codable.
struct Hello: Content {
let message = "Hello!"
}
router.get("greeting") { req in
return Hello() // {"message":"Hello!"}
}
Topics
Instance Methods
func afterDecode() throwsCalled after thisContentis decoded, generally from aRequestobject.func beforeEncode() throwsCalled before thisContentis encoded, generally for aResponseobject.
Type Properties
static var defaultContentType: HTTPMediaTypeThe defaultMediaTypeto use when encoding content. This can always be overridden at the encode call.
Relationships
Inherits From
RequestDecodableResponseEncodableSwift.DecodableSwift.EncodableSwift.SendableSwift.SendableMetatype
Conforming Types
ArrayBoolDictionaryDoubleFloatIntInt16Int32Int64Int8StringUIntUInt16UInt32UInt64UInt8