Vapor Documentation Beta

Class Request

public final class Request: CustomStringConvertible
%3 Request Request RequestDecodable RequestDecodable Request->RequestDecodable CustomStringConvertible CustomStringConvertible Request->CustomStringConvertible

Nested Types

Request.Authentication

Request helper for storing and fetching authenticated objects.

Request.Password
Request.Body

Conforms To

RequestDecodable
CustomStringConvertible

Initializers

init(application:​method:​url:​version:​headers:​collected​Body:​remote​Address:​logger:​on:​)

public 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"), on eventLoop: EventLoop)

init(application:​method:​url:​version:​headers​NoUpdate:​collected​Body:​remote​Address:​logger:​on:​)

public 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"), on eventLoop: EventLoop)

Properties

auth

var auth: Authentication

Helper for accessing authenticated objects. See Authenticator for more information.

client

var client: Client

password

var password: Password

application

let application: Application

method

var method: HTTPMethod

The HTTP method for this request.

httpReq.method = .GET

url

var url: URI

The URL used on this request.

version

var version: HTTPVersion

The version for this HTTP request.

headers

var headers: HTTPHeaders

The header fields for this HTTP request. The "Content-Length" and "Transfer-Encoding" headers will be set automatically when the body property is mutated.

route

var route: Route?

Route object we found for this request. This holds metadata that can be used for (for example) Metrics.

req.route?.description // "GET /hello/:name"

query

var query: URLQueryContainer

content

var content: ContentContainer

logger

var logger: Logger

body

var body: Body

cookies

var cookies: HTTPCookies

Get and set HTTPCookies for this HTTPRequest This accesses the "Cookie" header.

description

var description: String

See CustomStringConvertible

remote​Address

let remoteAddress: SocketAddress?

event​Loop

let eventLoop: EventLoop

parameters

var parameters: Parameters

storage

var storage: Storage

session

var session: Session

Returns the current Session or creates one.

router.get("session") { req -> String in
    req.session.data["name"] = "Vapor"
    return "Session set"
}

Returns

Session for this Request.

has​Session

var hasSession: Bool

fileio

var fileio: FileIO

view

var view: ViewRenderer

Methods

redirect(to:​type:​)

public func redirect(to location: String, type: RedirectType = .normal) -> Response

Creates a redirect Response.

router.get("redirect") { req in
    return req.redirect(to: "https://vapor.codes")
}

Set type to '.permanently' to allow caching to automatically redirect from browsers. Defaulting to non-permanent to prevent unexpected caching.

decode​Request(_:​)

public static func decodeRequest(_ request: Request) -> EventLoopFuture<Request>