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
func requireDecoder(for: HTTPMediaType) throws -> any ContentDecoderReturns aContentDecoderfor the specifiedHTTPMediaTypeor throws an error.func requireEncoder(for: HTTPMediaType) throws -> any ContentEncoderReturns anContentEncoderfor the specifiedHTTPMediaTypeor throws an error.func requireURLDecoder() throws -> any URLQueryDecoderReturns aURLQueryDecoderor throws an error.func requireURLEncoder() throws -> any URLQueryEncoderReturns aURLQueryEncoderor throws an error.func use(decoder: any ContentDecoder, for: HTTPMediaType)Adds aContentDecoderfor the specifiedHTTPMediaType.func use(encoder: any ContentEncoder, for: HTTPMediaType)Adds aContentEncoderfor the specifiedHTTPMediaType.func use(urlDecoder: any URLQueryDecoder)func use(urlEncoder: any URLQueryEncoder)
Type Properties
Type Methods
static func `default`() -> ContentConfigurationCreates aContentConfigurationcontaining all of Vapor’s default coders.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype