{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Droplet","type":"basic","slug":"application","excerpt":"","body":"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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Initialization\"\n}\n[/block]\nAs you have probably already seen, the only thing required to create an instance of `Droplet` is to import Vapor.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import Vapor\\n\\nlet drop = Droplet()\\n\\n// your magic here\\n\\ndrop.start()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nCreation of the `Droplet` normally happens in the `main.swift` file. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Environment\"\n}\n[/block]\nThis contains the current environment your application is running in. Usually development, testing, or production.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if drop.config.environment == .production {\\n    ...\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nLearn more about how to configure and use Environment in the Environment section of this guide.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Working Directory\"\n}\n[/block]\nThis 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. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"drop.workDir = \\\"/var/www/my-project/\\\"\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nYou can change the working directory programmatically, or override the default when executing.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"vapor run --workDir=\\\"/var/www/my-project\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Resources Directory\"\n}\n[/block]\nThe resources directory is a read only property that builds the path for the Resources directory from the Working Directory.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"print(drop.resourcesDir)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Customization\"\n}\n[/block]\nThe Droplet has several customizable properties.\n\nMost plugins for Vapor come with a `Provider`, these take care of configuration details for you. Read more about providers in the Providers section.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Droplet(\\n    workDir: String? = nil,\\n    config: Config? = nil,\\n    localization: Localization? = nil,\\n    hash: HashDriver? = nil,\\n    console: ConsoleDriver? = nil,\\n    server: ServerDriver.Type? = nil,\\n    router: RouterDriver? = nil,\\n    session: SessionDriver? = nil,\\n    providers: [Provider] = [],\\n    arguments: [String]? = nil\\n)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","updates":["570f29edd6c6f00e00b98709","5736f6e01a48812200566f23"],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"57841d7e2df749240067610a","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Guide","slug":"getting-started","order":1,"from_sync":false,"reference":false,"_id":"57841d7e2df74924006760ff","version":"57841d7e2df74924006760fd","project":"57086fe855a4690e005de407","createdAt":"2016-04-09T04:31:52.489Z","__v":0},"createdAt":"2016-04-09T19:18:15.036Z","user":"57086f3d447c410e00221bd1","__v":0,"githubsync":"","project":"57086fe855a4690e005de407","version":{"version":"0.14","version_clean":"0.14.0","codename":"","is_stable":false,"is_beta":true,"is_hidden":false,"is_deprecated":true,"categories":["57841d7e2df74924006760fe","57841d7e2df74924006760ff","57841d7e2df7492400676100","57841d7e2df7492400676101"],"_id":"57841d7e2df74924006760fd","createdAt":"2016-07-11T22:28:14.294Z","project":"57086fe855a4690e005de407","releaseDate":"2016-07-11T22:28:14.294Z","__v":1},"parentDoc":null}
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. [block:api-header] { "type": "basic", "title": "Initialization" } [/block] As you have probably already seen, the only thing required to create an instance of `Droplet` is to import Vapor. [block:code] { "codes": [ { "code": "import Vapor\n\nlet drop = Droplet()\n\n// your magic here\n\ndrop.start()", "language": "swift" } ] } [/block] Creation of the `Droplet` normally happens in the `main.swift` file. [block:api-header] { "type": "basic", "title": "Environment" } [/block] This contains the current environment your application is running in. Usually development, testing, or production. [block:code] { "codes": [ { "code": "if drop.config.environment == .production {\n ...\n}", "language": "swift" } ] } [/block] Learn more about how to configure and use Environment in the Environment section of this guide. [block:api-header] { "type": "basic", "title": "Working Directory" } [/block] 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. [block:code] { "codes": [ { "code": "drop.workDir = \"/var/www/my-project/\"", "language": "swift" } ] } [/block] You can change the working directory programmatically, or override the default when executing. [block:code] { "codes": [ { "code": "vapor run --workDir=\"/var/www/my-project\"", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Resources Directory" } [/block] The resources directory is a read only property that builds the path for the Resources directory from the Working Directory. [block:code] { "codes": [ { "code": "print(drop.resourcesDir)", "language": "swift" } ] } [/block] [block:api-header] { "type": "basic", "title": "Customization" } [/block] 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. [block:code] { "codes": [ { "code": "Droplet(\n workDir: String? = nil,\n config: Config? = nil,\n localization: Localization? = nil,\n hash: HashDriver? = nil,\n console: ConsoleDriver? = nil,\n server: ServerDriver.Type? = nil,\n router: RouterDriver? = nil,\n session: SessionDriver? = nil,\n providers: [Provider] = [],\n arguments: [String]? = nil\n)", "language": "swift" } ] } [/block]