-
Notifications
You must be signed in to change notification settings - Fork 14
HTTPBody
The contents of an HTTP request or response.
public struct HTTPBody: ExpressibleByStringLiteral
ExpressibleByStringLiteral
Creates a new body from a binary NIO.ByteBuffer
.
public init(buffer: ByteBuffer, mimeType: MIMEType? = nil)
- buffer: The buffer holding the data in the body.
- mimeType: The MIME type of data in the body.
Creates a new body containing the text with MIME type
text/plain
.
public init(text: String, mimeType: MIMEType = .plainText)
- text: The string contents of the body.
- mimeType: The media type of this text. Defaults to
.plainText
("text/plain").
Creates a new body from a binary Foundation.Data
.
public init(data: Data, mimeType: MIMEType? = nil)
- data: The data in the body.
- mimeType: The MIME type of the body.
Creates a body with a JSON object.
public init<E: Encodable>(json: E, encoder: JSONEncoder = Response.defaultJSONEncoder) throws
- json: The object to encode into the body.
- encoder: A customer encoder to encoder the JSON with. Defaults to
Response.defaultJSONEncoder
.
Any error thrown during encoding.
Create a body via a string literal.
public init(stringLiteral value: String)
- value: The string literal contents of the body.
The binary data in this body.
let buffer: ByteBuffer
The mime type of the data stored in this body. Used to set the
content-type
header when sending back a response.
let mimeType: MIMEType?
The contents of this body.
var data: Data
Decodes the body as a String
.
public func decodeString(with encoding: String.Encoding = .utf8) -> String?
- encoding: The
String.Encoding
value to decode with. Defaults to.utf8
.
The string decoded from the contents of this body.
Decodes the body as a JSON dictionary.
public func decodeJSONDictionary() throws -> [String: Any]?
If there's a error decoding the dictionary.
The dictionary decoded from the contents of this body.
Decodes the body as JSON into the provided Decodable type.
public func decodeJSON<D: Decodable>(as type: D.Type = D.self, with decoder: JSONDecoder = Request.defaultJSONDecoder) throws -> D
- type: The Decodable type to which the body should be decoded.
- decoder: The Decoder with which to decode. Defaults to
Request.defaultJSONEncoder
.
Any errors encountered during decoding.
The decoded object of type type
.
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