These docs are for v0.14. Click to read the latest docs for v0.16.

The Droplet is a core class that gives you access to many of Vapor's facilities. It is responsible for registering routes, starting the server, appending middleware, and more.

Initialization

As you have probably already seen, the only thing required to create an instance of Droplet is to import Vapor.

import Vapor

let drop = Droplet()

// your magic here

drop.start()

Creation of the Droplet normally happens in the main.swift file.

Environment

This contains the current environment your application is running in. Usually development, testing, or production.

if drop.config.environment == .production {
    ...
}

Learn more about how to configure and use Environment in the Environment section of this guide.

Working Directory

This property contains a path to the current working directory of the application relative to where it was started. By default, this property assumes you started the Droplet from its root directory.

drop.workDir = "/var/www/my-project/"

You can change the working directory programmatically, or override the default when executing.

vapor run --workDir="/var/www/my-project"

Resources Directory

The resources directory is a read only property that builds the path for the Resources directory from the Working Directory.

print(drop.resourcesDir)

Customization

The Droplet has several customizable properties.

Most plugins for Vapor come with a Provider, these take care of configuration details for you. Read more about providers in the Providers section.

Droplet(
    workDir: String? = nil,
    config: Config? = nil,
    localization: Localization? = nil,
    hash: HashDriver? = nil,
    console: ConsoleDriver? = nil,
    server: ServerDriver.Type? = nil,
    router: RouterDriver? = nil,
    session: SessionDriver? = nil,
    providers: [Provider] = [],
    arguments: [String]? = nil
)