Application
Core type representing a Vapor application.
final class Application
Core type representing a Vapor application.
final class Application
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.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol RoutesBuilder
protocol Sendable
static func make(_ environment: Environment = .development, _ eventLoopGroupProvider: EventLoopGroupProvider = .singleton) async throws -> Application
var allocator: ByteBufferAllocator { get }
var asyncCommands: AsyncCommands { get set }
var cache: Cache { get }
Current application cache. See Request.cache
for caching in request handlers.
var caches: Caches { get }
Controls application’s configured caches.
var client: Client { get }
var clients: Clients { get }
var commands: Commands { get set }
var console: Console { get set }
var didShutdown: Bool { get }
var directory: DirectoryConfiguration { get set }
var environment: Environment { get set }
let eventLoopGroup: EventLoopGroup
let eventLoopGroupProvider: EventLoopGroupProvider
var fileio: NonBlockingFileIO { get }
var http: HTTP { get }
var lifecycle: Lifecycle { get set }
var locks: Locks { get set }
var logger: Logger { get set }
var middleware: Middlewares { get set }
var password: Password { get }
var passwords: Passwords { get }
var responder: Responder { get }
var routes: Routes { get }
var running: Running? { get set }
var server: Server { get }
var servers: Servers { get }
var services: Services { get }
var sessions: Sessions { get }
var storage: Storage { get set }
var sync: NIOLock { get }
var threadPool: NIOThreadPool { get set }
The application thread pool. Vapor uses NIOSingletons.posixBlockingThreadPool
by default for this, which defaults to a thread pool of size equal to the number of available cores.
var traceAutoPropagation: Bool { get set }
If enabled, tracing propagation is automatically handled by restoring & setting request.serviceContext
automatically across Vapor-internal EventLoopFuture boundaries. If disabled, traces will not automatically nest, and the user should restore & set request.serviceContext
manually where needed. There are performance implications to enabling this feature.
var view: ViewRenderer { get }
var views: Views { get }
func add(_ route: Route)
func asyncBoot() async throws
Called when the applications starts up, will trigger the lifecycle handlers. The asynchronous version of boot
func asyncShutdown() async throws
func boot() throws
func execute() async throws
Starts the Application
asynchronous using the startup
method, then waits for any running tasks to complete. If your application is started without arguments, the default argument is used.
func run() throws
Starts the Application
using the start
method, then waits for any running tasks to complete. If your application is started without arguments, the default argument is used.
func shutdown()
func start() throws
When called, this will execute the startup command provided through an argument. If no startup command is provided, the default is used. Under normal circumstances, this will start running Vapor’s webserver.
func startup() async throws
When called, this will asynchronously execute the startup command provided through an argument. If no startup command is provided, the default is used. Under normal circumstances, this will start running Vapor’s webserver.
struct Caches
struct Clients
struct Core
enum EventLoopGroupProvider
struct HTTP
struct Lifecycle
final class Locks
struct Password
struct Passwords
struct Responder
struct Running
struct Servers
struct Service<ServiceType>
struct Services
struct Sessions
struct Views
convenience init(_ environment: Environment = .development, _ eventLoopGroupProvider: EventLoopGroupProvider = .singleton)
@discardableResult @preconcurrency func delete<Response>(_ path: PathComponent..., use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func delete<Response>(_ path: PathComponent..., use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func delete<Response>(_ path: [PathComponent], use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func delete<Response>(_ path: [PathComponent], use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func get<Response>(_ path: PathComponent..., use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func get<Response>(_ path: PathComponent..., use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func get<Response>(_ path: [PathComponent], use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func get<Response>(_ path: [PathComponent], use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
func group(_ path: PathComponent..., configure: (RoutesBuilder) throws -> ()) rethrows
Creates a new Router
that will automatically prepend the supplied path components.
func group(_ middleware: Middleware..., configure: (RoutesBuilder) throws -> ()) rethrows
Creates a new Router
wrapped in the supplied variadic Middleware
.
func group(_ path: [PathComponent], configure: (RoutesBuilder) throws -> ()) rethrows
Creates a new Router
that will automatically prepend the supplied path components.
func group(_ middleware: [Middleware], configure: (RoutesBuilder) throws -> ()) rethrows
Creates a new Router
wrapped in the supplied array of Middleware
.
func grouped(_ path: PathComponent...) -> RoutesBuilder
Creates a new Router
that will automatically prepend the supplied path components.
func grouped(_ middleware: Middleware...) -> RoutesBuilder
Creates a new Router
wrapped in the supplied variadic Middleware
.
func grouped(_ path: [PathComponent]) -> RoutesBuilder
Creates a new Router
that will automatically prepend the supplied path components.
func grouped(_ middleware: [Middleware]) -> RoutesBuilder
Creates a new Router
wrapped in the supplied array of Middleware
.
@discardableResult @preconcurrency func on<Response>(_ method: HTTPMethod, _ path: PathComponent..., body: HTTPBodyStreamStrategy = .collect, use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func on<Response>(_ method: HTTPMethod, _ path: PathComponent..., body: HTTPBodyStreamStrategy = .collect, use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func on<Response>(_ method: HTTPMethod, _ path: [PathComponent], body: HTTPBodyStreamStrategy = .collect, use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func on<Response>(_ method: HTTPMethod, _ path: [PathComponent], body: HTTPBodyStreamStrategy = .collect, use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func patch<Response>(_ path: PathComponent..., use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func patch<Response>(_ path: PathComponent..., use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func patch<Response>(_ path: [PathComponent], use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func patch<Response>(_ path: [PathComponent], use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func post<Response>(_ path: PathComponent..., use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func post<Response>(_ path: PathComponent..., use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func post<Response>(_ path: [PathComponent], use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func post<Response>(_ path: [PathComponent], use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func put<Response>(_ path: PathComponent..., use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func put<Response>(_ path: PathComponent..., use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
@discardableResult @preconcurrency func put<Response>(_ path: [PathComponent], use closure: @escaping (Request) throws -> Response) -> Route where Response : ResponseEncodable
@discardableResult @preconcurrency func put<Response>(_ path: [PathComponent], use closure: @escaping (Request) async throws -> Response) -> Route where Response : AsyncResponseEncodable
func register(collection: RouteCollection) throws
Registers all of the routes in the group to this router.
func responseCompression(_ override: HTTPHeaders.ResponseCompression, force shouldForce: Bool = false) -> RoutesBuilder
Override the response compression settings for a route.
@discardableResult @preconcurrency func webSocket(_ path: PathComponent..., maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) -> EventLoopFuture<HTTPHeaders?>) = {
$0.eventLoop.makeSucceededFuture([:])
}, onUpgrade: @escaping (Request, WebSocket) -> ()) -> Route
Adds a route for opening a web socket connection
@discardableResult @preconcurrency func webSocket(_ path: PathComponent..., maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) async throws -> HTTPHeaders?) = { _ in [:] }, onUpgrade: @escaping (Request, WebSocket) async -> ()) -> Route
Adds a route for opening a web socket connection
@discardableResult @preconcurrency func webSocket(_ path: [PathComponent], maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) -> EventLoopFuture<HTTPHeaders?>) = {
$0.eventLoop.makeSucceededFuture([:])
}, onUpgrade: @escaping (Request, WebSocket) -> ()) -> Route
Adds a route for opening a web socket connection
@discardableResult @preconcurrency func webSocket(_ path: [PathComponent], maxFrameSize: WebSocketMaxFrameSize = .`default`, shouldUpgrade: @escaping ((Request) async throws -> HTTPHeaders?) = { _ in [:] }, onUpgrade: @escaping (Request, WebSocket) async -> ()) -> Route
Adds a route for opening a web socket connection
import VaporTestUtils
struct InMemory
struct Live
enum Method
import VaporTesting
VaporTesting is a set of utilities to make writing unit tests for Vapor applications easy.
protocol TestingApplicationTester : Sendable
func performTest(request: TestingHTTPRequest) async throws -> TestingHTTPResponse
func testing(method: Method = .inMemory) throws -> TestingApplicationTester
func sendRequest(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, fileID: String = #fileID, filePath: String = #filePath, line: Int = #line, column: Int = #column, beforeRequest: (inout TestingHTTPRequest) async throws -> () = { _ in }) async throws -> TestingHTTPResponse
@discardableResult func test(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, fileID: String = #fileID, filePath: String = #filePath, line: Int = #line, column: Int = #column, afterResponse: (TestingHTTPResponse) async throws -> ()) async throws -> TestingApplicationTester
@discardableResult func test(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, fileID: String = #fileID, filePath: String = #filePath, line: Int = #line, column: Int = #column, beforeRequest: (inout TestingHTTPRequest) async throws -> () = { _ in }, afterResponse: (TestingHTTPResponse) async throws -> () = { _ in }) async throws -> TestingApplicationTester
import XCTVapor
XCTVapor is a set of utilities to make writing unit tests for Vapor applications easy.
protocol XCTApplicationTester : Sendable
func performTest(request: TestingHTTPRequest) throws -> TestingHTTPResponse
func performTest(request: TestingHTTPRequest) async throws -> TestingHTTPResponse
func testable(method: Method = .inMemory) throws -> XCTApplicationTester
func sendRequest(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, file: StaticString = #filePath, line: UInt = #line, beforeRequest: (inout XCTHTTPRequest) throws -> () = { _ in }) throws -> XCTHTTPResponse
@discardableResult func test(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, file: StaticString = #filePath, line: UInt = #line, afterResponse: (XCTHTTPResponse) throws -> ()) throws -> XCTApplicationTester
@discardableResult func test(_ method: HTTPMethod, _ path: String, headers: HTTPHeaders = [:], body: ByteBuffer? = nil, file: StaticString = #filePath, line: UInt = #line, beforeRequest: (inout XCTHTTPRequest) throws -> () = { _ in }, afterResponse: (XCTHTTPResponse) throws -> () = { _ in }) throws -> XCTApplicationTester