Vapor Documentation Beta

Class Request

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

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

public var auth: Authentication 

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

cache

public var cache: Cache 

client

public var client: Client 

password

public var password: Password 

application

public let application: Application

method

public var method: HTTPMethod

The HTTP method for this request.

httpReq.method = .GET

url

public var url: URI

The URL used on this request.

version

public var version: HTTPVersion

The version for this HTTP request.

headers

public 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

public 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

public var query: URLQueryContainer 

content

public var content: ContentContainer 

logger

public var logger: Logger

body

public var body: Body 

cookies

public var cookies: HTTPCookies 

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

description

public var description: String 

See CustomStringConvertible

remote​Address

public let remoteAddress: SocketAddress?

event​Loop

public let eventLoop: EventLoop

parameters

public var parameters: Parameters

storage

public var storage: Storage

session

public 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

public var hasSession: Bool 

fileio

public var fileio: FileIO 

view

public 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>