-
Notifications
You must be signed in to change notification settings - Fork 14
Response
A type representing the response from an HTTP endpoint. This
response can be a failure or success case depending on the
status code in the head.
public final class ResponseCreates a new response using a status code, headers and body.
If the headers do not contain content-length or
content-type, those will be appended based on
the supplied HTTPBody.
public init(status: HTTPResponseStatus, headers: HTTPHeaders = HTTPHeaders(), body: HTTPBody?)- status: The status code of this response.
- headers: Any headers to return in the response. Defaults to empty headers.
- body: The body of this response. See
HTTPBodyfor initializing with various data.
Initialize this response with a closure that will be called,
allowing you to directly write headers, body, and end to
the response. The request connection will be left open
until you .writeEnd() to the closure's
ResponseWriter.
public init(_ writer: @escaping (ResponseWriter) -> Void)Usage:
app.get("/stream") {
Response { writer in
writer.writeHead(...)
writer.writeBody(...)
writer.writeEnd()
}
}- writer: A closure take a
ResponseWriterand using it to write response data to a remote peer.
The default JSONEncoder with which to encode JSON responses.
var defaultJSONEncoderThe default response for when there is an error along the
routing chain that does not conform to
ResponseConvertible.
var defaultErrorResponseThe success or failure status response code.
var status: HTTPResponseStatusThe HTTP headers.
var headers: HTTPHeadersThe body which contains any data you want to send back to the client This can be HTML, an image or JSON among many other data types.
let body: HTTPBody?public func convert() throws -> EventLoopFuture<Response>Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue