requireDecoder(for:)
Returns a ContentDecoder
for the specified HTTPMediaType
or throws an error.
func requireDecoder(for mediaType: HTTPMediaType) throws -> ContentDecoder
let coder = try ContentConfiguration.global.requireDecoder(for: .json)
Returns a ContentDecoder
for the specified HTTPMediaType
or throws an error.
func requireDecoder(for mediaType: HTTPMediaType) throws -> ContentDecoder
s5Vapor20ContentConfigurationV14requireDecoder3forAA0bE0_pAA13HTTPMediaTypeV_tKF
What are these?2TJ
let coder = try ContentConfiguration.global.requireDecoder(for: .json)
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
struct ContentConfiguration
Configures which Encoder
s and Decoder
s to use when interacting with data in HTTP messages.
protocol ContentDecoder : Sendable
Conform a type to this protocol to make it usable for decoding data via Vapor’s ContentConfiguration
system.
struct HTTPMediaType
Represents an encoded data-format, used in HTTP, HTML, email, and elsewhere.
init()
Create a new, empty ContentConfiguration
.
static var global: ContentConfiguration { get set }
static func `default`() -> ContentConfiguration
Creates a ContentConfiguration
containing all of Vapor’s default coders.
func requireEncoder(for mediaType: HTTPMediaType) throws -> ContentEncoder
Returns an ContentEncoder
for the specified HTTPMediaType
or throws an error.
func requireURLDecoder() throws -> URLQueryDecoder
Returns a URLQueryDecoder
or throws an error.
func requireURLEncoder() throws -> URLQueryEncoder
Returns a URLQueryEncoder
or throws an error.
mutating func use(decoder: ContentDecoder, for mediaType: HTTPMediaType)
Adds a ContentDecoder
for the specified HTTPMediaType
.
mutating func use(encoder: ContentEncoder, for mediaType: HTTPMediaType)
Adds a ContentEncoder
for the specified HTTPMediaType
.
mutating func use(urlDecoder: URLQueryDecoder)
mutating func use(urlEncoder: URLQueryEncoder)