Skip to content

Structure

ContentConfiguration

Configures which Encoders and Decoders to use when interacting with data in HTTP messages.
struct ContentConfiguration

Overview

ContentConfiguration.global.use(encoder: JSONEncoder(), for: .json)

Each coder is registered to a specific HTTPMediaType. When decoding content from HTTP messages, the HTTPMediaType will be specified by the message itself. When encoding content from HTTP messages, the HTTPMediaType should be specified (HTTTMediaType/json is usually the assumed default).

try res.content.encode("hello", as: .plainText)
print(res.mediaType) // .plainText
print(res.body.string) // "hello"

Most often, these configured coders are used to encode and decode types conforming to Content. See the Content protocol for more information.

Topics

Initializers

Instance Methods

Type Properties

Type Methods

Relationships

Conforms To

  • Swift.Sendable
  • Swift.SendableMetatype