This commit is contained in:
tanner0101 2017-05-19 12:17:36 +01:00
parent 6f933845ee
commit 97c0a3779b
3 changed files with 128 additions and 4 deletions

View File

@ -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...",

View File

@ -522,11 +522,45 @@
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="toc">
<label class="md-nav__link md-nav__link--active" for="toc">
Package
</label>
<a href="./" title="Package" class="md-nav__link md-nav__link--active">
Package
</a>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#with-vapor" title="With Vapor" class="md-nav__link">
With Vapor
</a>
</li>
<li class="md-nav__item">
<a href="#without-vapor" title="Without Vapor" class="md-nav__link">
Without Vapor
</a>
</li>
</ul>
</nav>
</li>
@ -1473,6 +1507,27 @@
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#with-vapor" title="With Vapor" class="md-nav__link">
With Vapor
</a>
</li>
<li class="md-nav__item">
<a href="#without-vapor" title="Without Vapor" class="md-nav__link">
Without Vapor
</a>
</li>
</ul>
</nav>
</div>
@ -1487,7 +1542,29 @@
<h1 id="_1"><a class="headerlink" href="#_1" title="Permanent link">&para;</a></h1>
<h1 id="using-routing">Using Routing<a class="headerlink" href="#using-routing" title="Permanent link">&para;</a></h1>
<h2 id="with-vapor">With Vapor<a class="headerlink" href="#with-vapor" title="Permanent link">&para;</a></h2>
<p>This package is included with Vapor by default, just add:</p>
<div class="codehilite"><pre><span></span><span class="kd">import</span> <span class="nc">Routing</span>
</pre></div>
<h2 id="without-vapor">Without Vapor<a class="headerlink" href="#without-vapor" title="Permanent link">&para;</a></h2>
<p>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 <code>Package.swift</code> file.</p>
<div class="codehilite"><pre><span></span><span class="kd">import</span> <span class="nc">PackageDescription</span>
<span class="kd">let</span> <span class="nv">package</span> <span class="p">=</span> <span class="n">Package</span><span class="p">(</span>
<span class="n">name</span><span class="p">:</span> <span class="s">&quot;Project&quot;</span><span class="p">,</span>
<span class="n">dependencies</span><span class="p">:</span> <span class="p">[</span>
<span class="p">...</span>
<span class="p">.</span><span class="n">Package</span><span class="p">(</span><span class="n">url</span><span class="p">:</span> <span class="s">&quot;https://github.com/vapor/routing.git&quot;</span><span class="p">,</span> <span class="n">majorVersion</span><span class="p">:</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">],</span>
<span class="n">exclude</span><span class="p">:</span> <span class="p">[</span> <span class="p">...</span> <span class="p">]</span>
<span class="p">)</span>
</pre></div>
<p>Use <code>import Routing</code> to access Routing's APIs</p>
</article>

View File

@ -390,6 +390,8 @@
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="toc">
<a href="./" title="Log" class="md-nav__link md-nav__link--active">
Log
@ -1474,6 +1476,18 @@
<label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#protocol" title="Protocol" class="md-nav__link">
Protocol
</a>
</li>
</ul>
</nav>
</div>
</div>
@ -1489,7 +1503,20 @@
<h1>Log</h1>
<p>Logging...</p>
<p>Log information using <code>drop.log</code>.</p>
<div class="codehilite"><pre><span></span>drop.log.info(&quot;Informational log&quot;)
</pre></div>
<p>Log types supported are:
- info
- warning
- verbose
- debug
- error
- fatal</p>
<h2 id="protocol">Protocol<a class="headerlink" href="#protocol" title="Permanent link">&para;</a></h2>
<p>Create your own logger by conforming to <code>LogProtocol</code>. </p>
</article>