url
The URL used on this request.
var url: URI { get set }
The URL used on this request.
var url: URI { get set }
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
final class Request
Represents an HTTP request in an application.
struct URI
A type for constructing and manipulating (most) Uniform Resource Indicators.
convenience init(application: Application, method: HTTPMethod = .GET, url: URI = "/", version: HTTPVersion = .init(major: 1, minor: 1), headers: HTTPHeaders = .init(), collectedBody: ByteBuffer? = nil, remoteAddress: SocketAddress? = nil, logger: Logger = .init(label: "codes.vapor.request"), byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(), on eventLoop: EventLoop)
init(application: Application, method: HTTPMethod, url: URI, version: HTTPVersion = .init(major: 1, minor: 1), headersNoUpdate headers: HTTPHeaders = .init(), collectedBody: ByteBuffer? = nil, remoteAddress: SocketAddress? = nil, logger: Logger = .init(label: "codes.vapor.request"), byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(), on eventLoop: EventLoop)
static func decodeRequest(_ request: Request) -> EventLoopFuture<Request>
static func decodeRequest(_ request: Request) async throws -> Request
let application: Application
var auth: Authentication { get }
Helper for accessing authenticated objects. See Authenticator
for more information.
var body: Body { get }
var byteBufferAllocator: ByteBufferAllocator { get set }
var cache: Cache { get }
var client: Client { get }
var content: ContentContainer { get set }
This container is used to read your Decodable
type using a ContentDecoder
implementation. If no ContentDecoder
is provided, a Request
’s Content-Type
header is used to select a registered decoder.
var cookies: HTTPCookies { get set }
Get and set HTTPCookies
for this Request
This accesses the "Cookie"
header.
var description: String { get }
See CustomStringConvertible
let eventLoop: EventLoop
The EventLoop
which is handling this Request
. The route handler and any relevant middleware are invoked in this event loop.
var fileio: FileIO { get }
var hasSession: Bool { get }
var headers: HTTPHeaders { get set }
The header fields for this HTTP request. The "Content-Length"
and "Transfer-Encoding"
headers will be set automatically when the body
property is mutated.
let id: String
A unique ID for the request.
var logger: Logger { get set }
This Logger from Apple’s swift-log
Package is preferred when logging in the context of handing this Request. Vapor already provides metadata to this logger so that multiple logged messages can be traced back to the same request.
var method: HTTPMethod { get set }
The HTTP method for this request.
var parameters: Parameters { get set }
A container containing the route parameters that were captured when receiving this request. Use this container to grab any non-static parameters from the URL, such as model IDs in a REST API.
var password: Password { get }
var peerAddress: SocketAddress? { get }
We try to determine true peer address if load balancer or reversed proxy provided info in headers
var query: URLQueryContainer { get set }
let remoteAddress: SocketAddress?
The address from which this HTTP request was received by SwiftNIO. This address may not represent the original address of the peer, especially if Vapor receives its requests through a reverse-proxy such as nginx.
var route: Route? { get set }
Route object we found for this request. This holds metadata that can be used for (for example) Metrics.
var serviceContext: ServiceContext { get set }
var services: Services { get }
var session: Session { get }
Returns the current Session
or creates one.
var storage: Storage { get set }
This container is used as arbitrary request-local storage during the request-response lifecycle.Z
var version: HTTPVersion { get set }
The version for this HTTP request.
var view: ViewRenderer { get }
func redirect(to location: String, redirectType: Redirect = .normal) -> Response
Creates a redirect Response
.
@preconcurrency func webSocket(maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) -> EventLoopFuture<HTTPHeaders?>) = {
$0.eventLoop.makeSucceededFuture([:])
}, onUpgrade: @escaping (Request, WebSocket) -> ()) -> Response
@preconcurrency func webSocket(maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) async throws -> HTTPHeaders?) = { _ in [:] }, onUpgrade: @escaping (Request, WebSocket) async -> ()) -> Response
Upgrades an existing request to a websocket connection
struct Authentication
Request helper for storing and fetching authenticated objects.
struct Body
struct Password
struct Services
func redirect(to location: String, type: RedirectType) -> Response
Creates a redirect Response
.