Vapor Documentation

Protocol Response​Encodable

public protocol ResponseEncodable  

Can convert self to a Response.

Types that conform to this protocol can be returned in route closures.

%11 ResponseEncodable ResponseEncodable Response Response Response->ResponseEncodable Content Content Content->ResponseEncodable AnyResponse AnyResponse AnyResponse->ResponseEncodable ClientResponse ClientResponse ClientResponse->ResponseEncodable View View View->ResponseEncodable

Types Conforming to Response​Encodable

ClientResponse
Content

Convertible to / from content in an HTTP message.

Response

An HTTP response from a server back to the client.

AnyResponse

A type erased response useful for routes that can return more than one type.

View

Default Implementations

encode​Response(status:​headers:​for:​)

public func encodeResponse(status: HTTPStatus, headers: HTTPHeaders = [:], for request: Request) -> EventLoopFuture<Response>  

Asynchronously encodes Self into a Response, setting the supplied status and headers.

router.post("users") { req -> EventLoopFuture<Response> in
    return try req.content
        .decode(User.self)
        .save(on: req)
        .encode(status: .created, for: req)
}

Parameters

status HTTPStatus

HTTPStatus to set on the Response.

headers HTTPHeaders

HTTPHeaders to merge into the Response's headers.

Returns

Newly encoded Response.

Requirements

encode​Response(for:​)

func encodeResponse(for request: Request) -> EventLoopFuture<Response>

Encodes an instance of Self to a Response.

Parameters

for Request

The Request associated with this Response.

Returns

A Response.