Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Structure

ContentConfiguration

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

Overview

var contentConfig = ContentConfiguration()
contentConfig.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 Methods

Relationships

Conforms To

  • Swift.Sendable
  • Swift.SendableMetatype