Instance Methodvapor 4.114.1Vapor

encodeResponse(status:headers:for:)

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

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

Parameters

status

HTTPStatus to set on the Response.

headers

HTTPHeaders to merge into the Response’s headers.

Returns

Newly encoded Response.

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