ContentConfiguration
ContentConfiguration.swift:19struct ContentConfiguration
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.