Response
An HTTP response from a server back to the client.
final class Response
let res = Response(status: .ok)
See HTTPClient
and HTTPServer
.
An HTTP response from a server back to the client.
final class Response
let res = Response(status: .ok)
See HTTPClient
and HTTPServer
.
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.
protocol AsyncResponseEncodable
Can convert self
to a Response
.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Escapable
protocol ResponseEncodable
Can convert self
to a Response
.
protocol Sendable
convenience init(status: HTTPResponseStatus = .ok, version: HTTPVersion = .init(major: 1, minor: 1), headers: HTTPHeaders = .init(), body: Body = .empty)
Creates a new Response
.
init(status: HTTPResponseStatus, version: HTTPVersion, headersNoUpdate headers: HTTPHeaders, body: Body)
Internal init that creates a new Response
without sanitizing headers.
var body: Body { get set }
The Body
. Updating this property will also update the associated transport headers.
var content: ContentContainer { get set }
var cookies: HTTPCookies { get set }
Get and set HTTPCookies
for this Response
. This accesses the "Set-Cookie"
header.
var description: String { get }
See CustomStringConvertible
var headers: HTTPHeaders { get set }
The header fields for this HTTP response. The "Content-Length"
and "Transfer-Encoding"
headers will be set automatically when the body
property is mutated.
var status: HTTPResponseStatus { get set }
The HTTP response status.
var storage: Storage { get set }
var upgrader: Upgrader? { get set }
Optional Upgrade behavior to apply to this response. currently, websocket upgrades are the only defined case.
var version: HTTPVersion { get set }
The HTTP version that corresponds to this response.
func encodeResponse(for request: Request) -> EventLoopFuture<Response>
func encodeResponse(for request: Request) async throws -> Response
struct Body
Represents a Response
’s body.
func encodeResponse(status: HTTPStatus, headers: HTTPHeaders = [:], for request: Request) -> EventLoopFuture<Response>
Asynchronously encodes Self
into a Response
, setting the supplied status and headers.