Skip to content

Protocol

Content

Convertible to / from content in an HTTP message.
protocol Content : Decodable, Encodable, Sendable, AsyncRequestDecodable, AsyncResponseEncodable, RequestDecodable, ResponseEncodable

Overview

Conformance to this protocol consists of:

  • Codable

  • RequestDecodable

  • ResponseEncodable

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

  • afterDecode()
    Called after this Content is decoded, generally from a Request object.
  • beforeEncode()
    Called before this Content is encoded, generally for a Response object.

Type Properties

  • defaultContentType
    The default MediaType to use when encoding content. This can always be overridden at the encode call.

Relationships

Inherits From

Conforming Types