Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Instance Method

encodeResponse(status:headers:for:)

Asynchronously encodes Self into a Response, setting the supplied status and headers.
func encodeResponse(status: HTTPResponse.Status, headers: HTTPFields = [:], for request: Request) async throws -> Response

Parameters

status

HTTPResponse.Status to set on the Response.

headers

HTTPFields to merge into the Response’s headers.

Return Value

Newly encoded Response.

Discussion

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