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
init()Create a new, emptyContentConfiguration.
Instance Methods
requireDecoder(for:)Returns aContentDecoderfor the specifiedHTTPMediaTypeor throws an error.requireEncoder(for:)Returns anContentEncoderfor the specifiedHTTPMediaTypeor throws an error.requireURLDecoder()Returns aURLQueryDecoderor throws an error.requireURLEncoder()Returns aURLQueryEncoderor throws an error.use(decoder:for:)Adds aContentDecoderfor the specifiedHTTPMediaType.use(encoder:for:)Adds aContentEncoderfor the specifiedHTTPMediaType.use(urlDecoder:)use(urlEncoder:)
Type Properties
Type Methods
default()Creates aContentConfigurationcontaining all of Vapor’s default coders.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype