diff --git a/build/2.0/mkdocs/search_index.json b/build/2.0/mkdocs/search_index.json index 41ae57a0..09d4d226 100644 --- a/build/2.0/mkdocs/search_index.json +++ b/build/2.0/mkdocs/search_index.json @@ -652,9 +652,14 @@ }, { "location": "/vapor/log/", - "text": "Logging...", + "text": "Log information using \ndrop.log\n.\n\n\ndrop.log.info(\nInformational log\n)\n\n\n\n\n\nLog types supported are:\n- info\n- warning\n- verbose\n- debug\n- error\n- fatal\n\n\nProtocol\n\n\nCreate your own logger by conforming to \nLogProtocol\n.", "title": "Log" }, + { + "location": "/vapor/log/#protocol", + "text": "Create your own logger by conforming to LogProtocol .", + "title": "Protocol" + }, { "location": "/vapor/commands/", "text": "Warning\n\n\nThis section may contain outdated information.\n\n\n\n\nCommands\n\n\nCustom console commands on Vapor are a breeze.\n\n\nExample\n\n\nTo make a custom console command we must first create a new \n.swift\n file, import \nVapor\n and \nConsole\n, and implement the \nCommand\n protocol.\n\n\nimport\n \nVapor\n\n\nimport\n \nConsole\n\n\n\nfinal\n \nclass\n \nMyCustomCommand\n:\n \nCommand\n \n{\n\n \npublic\n \nlet\n \nid\n \n=\n \ncommand\n\n \npublic\n \nlet\n \nhelp\n \n=\n \n[\nThis command does things, like foo, and bar.\n]\n\n \npublic\n \nlet\n \nconsole\n:\n \nConsoleProtocol\n\n\n \npublic\n \ninit\n(\nconsole\n:\n \nConsoleProtocol\n)\n \n{\n\n \nself\n.\nconsole\n \n=\n \nconsole\n\n \n}\n\n\n \npublic\n \nfunc\n \nrun\n(\narguments\n:\n \n[\nString\n])\n \nthrows\n \n{\n\n \nconsole\n.\nprint\n(\nrunning custom command...\n)\n\n \n}\n\n\n}\n\n\n\n\n\n\n\n\nThe \nid\n property is the string you will type in the console to access the command. \n.build/debug/App command\n will run the Custom Command.\n\n\nThe \nhelp\n property is the help message that will give your custom command's users some idea of how to access it.\n\n\nThe \nconsole\n property is the object passed to your custom command that adheres to the console protocol, allowing manipulation of the console.\n\n\nThe \nrun\n method is where you put the logic relating to your command.\n\n\n\n\nAfter we work our magic in the Custom Command file, we switch over to our \nmain.swift\n file and add the custom command to the droplet like so.\n\n\ndrop\n.\ncommands\n.\nappend\n(\nMyCustomCommand\n(\nconsole\n:\n \ndrop\n.\nconsole\n))\n\n\n\n\n\n\nThis allows Vapor access to our custom command and lets it know to display it in the \n--help\n section of the program.\n\n\nAfter compiling the application we can run our custom command like so.\n\n\n.build/debug/App command", @@ -787,9 +792,24 @@ }, { "location": "/routing/package/", - "text": "", + "text": "Using Routing\n\n\nWith Vapor\n\n\nThis package is included with Vapor by default, just add:\n\n\nimport\n \nRouting\n\n\n\n\n\n\nWithout Vapor\n\n\nRouting providers a performant, pure-Swift router to use in any server-side Swift project. To include it in your package, add the following to your \nPackage.swift\n file.\n\n\nimport\n \nPackageDescription\n\n\n\nlet\n \npackage\n \n=\n \nPackage\n(\n\n \nname\n:\n \nProject\n,\n\n \ndependencies\n:\n \n[\n\n \n...\n\n \n.\nPackage\n(\nurl\n:\n \nhttps://github.com/vapor/routing.git\n,\n \nmajorVersion\n:\n \n2\n)\n\n \n],\n\n \nexclude\n:\n \n[\n \n...\n \n]\n\n\n)\n\n\n\n\n\n\nUse \nimport Routing\n to access Routing's APIs", "title": "Package" }, + { + "location": "/routing/package/#using-routing", + "text": "", + "title": "Using Routing" + }, + { + "location": "/routing/package/#with-vapor", + "text": "This package is included with Vapor by default, just add: import Routing", + "title": "With Vapor" + }, + { + "location": "/routing/package/#without-vapor", + "text": "Routing providers a performant, pure-Swift router to use in any server-side Swift project. To include it in your package, add the following to your Package.swift file. import PackageDescription let package = Package ( \n name : Project , \n dependencies : [ \n ... \n . Package ( url : https://github.com/vapor/routing.git , majorVersion : 2 ) \n ], \n exclude : [ ... ] ) Use import Routing to access Routing's APIs", + "title": "Without Vapor" + }, { "location": "/routing/overview/", "text": "Basic Routing\n\n\nRouting is one of the most critical parts of a web framework. The router decides which requests get which responses.\n\n\nVapor has a plethora of functionality for routing including route builders, groups, and collections. In this section, we will look at the basics of routing.\n\n\nRegister\n\n\nThe most basic route includes a method, path, and closure.\n\n\ndrop\n.\nget\n(\nwelcome\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nHello\n\n\n}\n\n\n\n\n\n\nThe standard HTTP methods are available including \nget\n, \npost\n, \nput\n, \npatch\n, \ndelete\n, and \noptions\n.\n\n\ndrop\n.\npost\n(\nform\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nSubmitted with a POST request\n\n\n}\n\n\n\n\n\n\nNesting\n\n\nTo nest paths (adding \n/\ns in the URL), simply add commas.\n\n\ndrop\n.\nget\n(\nfoo\n,\n \nbar\n,\n \nbaz\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nYou requested /foo/bar/baz\n\n\n}\n\n\n\n\n\n\nYou can also use \n/\n, but commas are often easier to type and work better with type safe route \nparameters\n.\n\n\nAlternate\n\n\nAn alternate syntax that accepts a \nMethod\n as the first parameter is also available.\n\n\ndrop\n.\nadd\n(.\ntrace\n,\n \nwelcome\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nHello\n\n\n}\n\n\n\n\n\n\nThis may be useful if you want to register routes dynamically or use a less common method.\n\n\nRequest\n\n\nEach route closure is given a single \nRequest\n. This contains all of the data associated with the request that led to your route closure being called.\n\n\nResponse Representable\n\n\nA route closure can return in three ways:\n\n\n\n\nResponse\n\n\nResponseRepresentable\n\n\nthrow\n\n\n\n\nResponse\n\n\nA custom \nResponse\n can be returned.\n\n\ndrop\n.\nget\n(\nvapor\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nResponse\n(\nredirect\n:\n \nhttp://vapor.codes\n)\n\n\n}\n\n\n\n\n\n\nThis is useful for creating special responses like redirects. It is also useful for cases where you want to add cookies or other items to the response.\n\n\nResponse Representable\n\n\nAs you have seen in the previous examples, \nString\ns can be returned in route closures. This is because they conform to \nResponseRepresentable\n\n\nA lot of types in Vapor conform to this protocol by default:\n- String\n- Int\n- \nJSON\n\n- \nModel\n\n\ndrop\n.\nget\n(\njson\n)\n \n{\n \nrequest\n \nin\n\n \nvar\n \njson\n \n=\n \nJSON\n()\n\n \ntry\n \njson\n.\nset\n(\nnumber\n,\n \n123\n)\n\n \ntry\n \njson\n.\nset\n(\ntext\n,\n \nunicorns\n)\n\n \ntry\n \njson\n.\nset\n(\nbool\n,\n \nfalse\n)\n\n \nreturn\n \njson\n\n\n}\n\n\n\n\n\n\nThrowing\n\n\nIf you are unable to return a response, you may \nthrow\n any object that conforms to \nError\n. Vapor comes with a default error enum \nAbort\n.\n\n\ndrop\n.\nget\n(\n404\n)\n \n{\n \nrequest\n \nin\n\n \nthrow\n \nAbort\n(.\nnotFound\n)\n\n\n}\n\n\n\n\n\n\nYou can customize the message of these errors by using \nAbort\n\n\ndrop\n.\nget\n(\nerror\n)\n \n{\n \nrequest\n \nin\n\n \nthrow\n \nAbort\n(.\nbadRequest\n,\n \nreason\n:\n \nSorry \ud83d\ude31\n)\n\n\n}\n\n\n\n\n\n\nThese errors are caught by default in the \nErrorMiddleware\n where they are turned into a JSON response like the following.\n\n\n{\n\n \nerror:\n \ntrue,\n\n \nmessage:\n \nthe message\n\n\n}\n\n\n\n\n\n\nIf you want to override this behavior, remove the \nErrorMiddleware\n (key: \n\"error\"\n) from the \nDroplet\n's middleware and add your own.\n\n\nFallback\n\n\nFallback routes allow you to match multiple layers of nesting slashes.\n\n\napp\n.\nget\n(\nanything\n,\n \n*\n)\n \n{\n \nrequest\n \nin\n\n \nreturn\n \nMatches anything after /anything\n\n\n}\n\n\n\n\n\n\nFor example, the above route matches all of the following and more:\n\n\n\n\n/anything\n\n\n/anything/foo\n\n\n/anything/foo/bar\n\n\n/anything/foo/bar/baz\n\n\n...", diff --git a/build/2.0/routing/package/index.html b/build/2.0/routing/package/index.html index a754ad92..e9d22c90 100644 --- a/build/2.0/routing/package/index.html +++ b/build/2.0/routing/package/index.html @@ -522,11 +522,45 @@ + + + + Package + + + @@ -1473,6 +1507,27 @@ @@ -1487,7 +1542,29 @@ -

+

Using Routing

+

With Vapor

+

This package is included with Vapor by default, just add:

+
import Routing
+
+ + +

Without Vapor

+

Routing providers a performant, pure-Swift router to use in any server-side Swift project. To include it in your package, add the following to your Package.swift file.

+
import PackageDescription
+
+let package = Package(
+    name: "Project",
+    dependencies: [
+        ...
+        .Package(url: "https://github.com/vapor/routing.git", majorVersion: 2)
+    ],
+    exclude: [ ... ]
+)
+
+ + +

Use import Routing to access Routing's APIs

diff --git a/build/2.0/vapor/log/index.html b/build/2.0/vapor/log/index.html index ccf6b0a7..f32e8e57 100644 --- a/build/2.0/vapor/log/index.html +++ b/build/2.0/vapor/log/index.html @@ -390,6 +390,8 @@ + + Log @@ -1474,6 +1476,18 @@ + + + @@ -1489,7 +1503,20 @@

Log

-

Logging...

+

Log information using drop.log.

+
drop.log.info("Informational log")
+
+ + +

Log types supported are: +- info +- warning +- verbose +- debug +- error +- fatal

+

Protocol

+

Create your own logger by conforming to LogProtocol.