mirror of https://github.com/vapor/docs.git
573 lines
26 KiB
HTML
573 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>Vapor Documentation</title>
|
|
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Code+Pro">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Quicksand:400,700,300">
|
|
<link rel="stylesheet" href="/1.5/styles/vapor-code.css">
|
|
<link rel="stylesheet" href="/1.5/styles/main.css">
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<a class="logo" href="/1.5/">
|
|
<img src="/1.5/images/droplet.svg" alt="Vapor">
|
|
<h1>Vapor <em>Docs</em></h1>
|
|
</a>
|
|
<ul>
|
|
<li>
|
|
<a href="http://vapor.codes">Home</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://example.vapor.codes">Example</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/vapor/vapor">GitHub</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://twitter.com/@codevapor">Twitter</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://vapor.team">Slack</a>
|
|
</li>
|
|
</ul>
|
|
</header>
|
|
|
|
|
|
|
|
<nav>
|
|
<a href="#" class="toggle show">☰</a>
|
|
<a href="#" class="toggle close">×</a>
|
|
|
|
<div class="scroll">
|
|
<section>
|
|
<h3>Getting Started</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/install-swift-3-macos.html">
|
|
Install Swift 3: macOS
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/install-swift-3-ubuntu.html">
|
|
Install Swift 3: Ubuntu
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/install-toolbox.html">
|
|
Install Toolbox
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/hello-world.html">
|
|
Hello, World
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/manual.html">
|
|
Manual
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/getting-started/xcode.html">
|
|
Xcode
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Guide</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/guide/droplet.html">
|
|
Droplet
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/folder-structure.html">
|
|
Folder Structure
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/json.html">
|
|
JSON
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/config.html">
|
|
Config
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/views.html">
|
|
Views
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/leaf.html">
|
|
Leaf
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/controllers.html">
|
|
Controllers
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/middleware.html">
|
|
Middleware
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/validation.html">
|
|
Validation
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/provider.html">
|
|
Provider
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/sessions.html">
|
|
Sessions
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/hash.html">
|
|
Hash
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/guide/commands.html">
|
|
Commands
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Routing</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/routing/basic.html">
|
|
Basic
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/routing/parameters.html">
|
|
Route Parameters
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/routing/query-parameters.html">
|
|
Query Parameters
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/routing/group.html">
|
|
Group
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/routing/collection.html">
|
|
Collection
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Fluent</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/fluent/driver.html">
|
|
Driver
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/fluent/model.html">
|
|
Model
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/fluent/query.html">
|
|
Query
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/fluent/relation.html">
|
|
Relation
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Auth</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/auth/user.html">
|
|
User
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/auth/middleware.html">
|
|
Middleware
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/auth/request.html">
|
|
Request
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/auth/protect.html">
|
|
Protect
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>HTTP</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/http/request.html">
|
|
Request
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/response.html">
|
|
Response
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/body.html">
|
|
Body
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/response-representable.html">
|
|
ResponseRepresentable
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/responder.html">
|
|
Responder
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/client.html">
|
|
Client
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/server.html">
|
|
Server
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/http/cors.html">
|
|
CORS
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>WebSockets</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/websockets/droplet.html">
|
|
Droplet
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/websockets/custom.html">
|
|
Custom
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Testing</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/testing/modules.html">
|
|
Modules
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/testing/basic.html">
|
|
Basic
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Deploy</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/deploy/nginx.html">
|
|
Nginx
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/deploy/supervisor.html">
|
|
Supervisor
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h3>Version (1.5)</h3>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/1.5/switch/1_5.html">
|
|
1.5
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/1.5/switch/2_0.html">
|
|
2.0
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</div>
|
|
</nav>
|
|
|
|
<main>
|
|
<a href="https://github.com/vapor/documentation/blob/master/CONTRIBUTING.md" class="edit">✎ Edit on GitHub</a>
|
|
<h1 id="vapor-documentation">Vapor Documentation</h1>
|
|
<p><a href="http://stackoverflow.com/questions/tagged/vapor"><img src="https://img.shields.io/stackexchange/stackoverflow/t/vapor.svg" alt="Stack Overflow" /></a></p>
|
|
<p>This is the documentation for Vapor, a Web Framework for Swift that works on iOS, macOS, and Ubuntu; and all of the packages that Vapor offers.</p>
|
|
<p>Vapor is the most used web framework for Swift. It provides a beautifully expressive and easy to use foundation for your next website or API.</p>
|
|
<p>To view the framework's source code and code documentation, visit <a href="https://github.com/vapor/vapor">Vapor's GitHub</a>.</p>
|
|
<p>Read this in <a href="https://github.com/vapor/documentation/1.5/readme.es.html">Spanish</a></p>
|
|
<p>Read this in <a href="https://github.com/vapor/documentation/1.5/readme.zh-hant.html">正體中文</a></p>
|
|
<p>Read this in <a href="https://github.com/vapor/documentation/1.5/readme.zh-cn.html">简体中文</a></p>
|
|
<h2 id="how-to-read">How To Read</h2>
|
|
<p>You can read this guide by clicking through the folders and markdown files on <a href="https://github.com/vapor/documentation">GitHub</a> or through the rendered <a href="https://vapor.github.io/documentation/">GitHub Pages</a>.</p>
|
|
<h2 id="api">API</h2>
|
|
<p>Auto-generated API documentation is located at <a href="http://api.vapor.codes">api.vapor.codes</a>.</p>
|
|
<h2 id="packages">Packages</h2>
|
|
<p>Here are a list of all the packages and modules included with Vapor (also useable individually).</p>
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/vapor">Vapor</a>: Swift's most used web framework.
|
|
<ul>
|
|
<li>Auth: User authentication and persistance.</li>
|
|
<li>Sessions: Secure, ephemeral cookie based data storage.</li>
|
|
<li>Cookies: HTTP cookies.</li>
|
|
<li>Routing: Advanced router with type-safe parameterization.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/fluent">Fluent</a>: Models, relationships, and querying for NoSQL and SQL databases.</li>
|
|
<li><a href="https://github.com/vapor/engine">Engine</a>: Core transport layers.
|
|
<ul>
|
|
<li>HTTP: Pure Swift HTTP client and server.</li>
|
|
<li>URI: Pure Swift URI parsing and serializing.</li>
|
|
<li>WebSockets: Full-duplex communication channels over a single TCP connection.</li>
|
|
<li>SMTP: Send email using Sendgrid and Gmail.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/multipart">Multipart</a>: Fast, streaming, non-blocking multipart parser and serializer.
|
|
<ul>
|
|
<li>Multipart: Parses and serializes <code>multipart/mixed</code>.</li>
|
|
<li>FormData: Parses and serializes <code>multipart/form-data</code>.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/leaf">Leaf</a>: An extensible templating language.</li>
|
|
<li><a href="https://github.com/vapor/json">JSON</a>: Maps Jay JSON to Vapor types.</li>
|
|
<li><a href="https://github.com/vapor/console">Console</a>: Swift wrapper for console IO and commands.</li>
|
|
<li><a href="https://github.com/vapor/tls">TLS</a>: Swift wrapper for CLibreSSL's new TLS.</li>
|
|
<li><a href="https://github.com/vapor/crypto">Crypto</a>: Cryptography from LibreSSL and Swift.
|
|
<ul>
|
|
<li>Digests: Hashing with and without authentication.</li>
|
|
<li>Ciphers: Encryption and decryption</li>
|
|
<li>Random: Pseudo and cryptographically secure randomness.</li>
|
|
<li>BCrypt: Pure Swift implementation.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/node">Node</a>: Data structure for easy type conversions.
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/polymorphic">Polymorphic</a>: Syntax for easily accessing values from common types like JSON.</li>
|
|
<li><a href="https://github.com/vapor/path-indexable">Path Indexable</a>: A protocol for powerful subscript access of common types like JSON.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/core">Core</a>: Core extensions, type-aliases, and functions that facilitate common tasks.</li>
|
|
<li><a href="https://github.com/vapor/socks">Socks</a>: Swift C Socket API wrapper.</li>
|
|
</ul>
|
|
<h2 id="providers-amp-other">Providers & Other</h2>
|
|
<p>Here are a list of providers and third party packages that work great with Vapor.</p>
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/mysql">MySQL</a>: Robust MySQL interface for Swift.
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/mysql-driver">MySQL Driver</a>: MySQL driver for Fluent.</li>
|
|
<li><a href="https://github.com/vapor/mysql-provider">MySQL Provider</a>: MySQL provider for Vapor.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/sqlite">SQLite</a>: SQLite 3 wrapper for Swift
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/sqlite-driver">SQLite Driver</a>: SQLite driver for Fluent.</li>
|
|
<li><a href="https://github.com/vapor/sqlite-provider">SQLite Provider</a>: SQLite provider for Vapor.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/postgresql">PostgreSQL</a>: Robust PostgreSQL interface for Swift.
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/postgresql-driver">PostgreSQL Driver</a>: PostgreSQL driver for Fluent.</li>
|
|
<li><a href="https://github.com/vapor/postgresql-provider">PostgreSQL Provider</a>: PostgreSQL provider for Vapor.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/OpenKitten/MongoKitten">MongoKitten*</a>: Native MongoDB driver for Swift, written in Swift
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/mongo-driver">Mongo Driver</a>: MongoKitten driver for Fluent.</li>
|
|
<li><a href="https://github.com/vapor/mongo-provider">Mongo Provider</a>: MongoKitten provider for Vapor.</li>
|
|
<li><a href="https://github.com/OpenKitten/MainecoonVapor">MainecoonVapor</a>: MongoKitten ORM for Vapor.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/redbird">Redbird</a>: Pure-Swift Redis client implemented from the original protocol spec..
|
|
<ul>
|
|
<li><a href="https://github.com/vapor/redis-provider">Redis Provider</a>: Redis cache provider for Vapor.</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/vapor/kitura-provider">Kitura Provider</a>: Use IBM's Kitura HTTP server in Vapor.</li>
|
|
<li><a href="https://github.com/SwiftyBeaver/SwiftyBeaver-Vapor">SwiftyBeaver</a>: Adds the powerful logging of SwiftyBeaver to Vapor.</li>
|
|
<li><a href="https://github.com/matthijs2704/vapor-apns">APNS</a>: Simple APNS Library for Vapor (Swift).</li>
|
|
<li><a href="https://github.com/mdab121/vapor-fcm">VaporFCM</a>: Simple FCM (iOS + Android Push Notifications) library built for Vapor in Swift.</li>
|
|
<li><a href="https://github.com/siemensikkema/vapor-jwt">JWT</a>: JWT implementation for Vapor.</li>
|
|
<li><a href="https://github.com/JustinM1/VaporS3Signer">VaporS3Signer</a>: Generate V4 Auth Header/Pre-Signed URL for AWS S3 REST API</li>
|
|
<li><a href="https://github.com/jakeheis/Flock">Flock</a>: Automated deployment of Swift projects to servers
|
|
<ul>
|
|
<li><a href="https://github.com/jakeheis/VaporFlock">VaporFlock</a>: Use Flock to deploy Vapor applications</li>
|
|
</ul></li>
|
|
<li><a href="https://github.com/bygri/vapor-forms">VaporForms</a>: Brings simple, dynamic and re-usable web form handling to Vapor.</li>
|
|
<li><a href="https://github.com/BrettRToomey/Jobs">Jobs</a>: A minimalistic job/background-task system for Swift.</li>
|
|
<li><a href="https://github.com/himani93/heimdall">Heimdall</a>: An easy to use HTTP request logger.</li>
|
|
</ul>
|
|
<h2 id="authors">Authors</h2>
|
|
<p><a href="mailto:tanner@qutheory.io">Tanner Nelson</a>, <a href="mailto:logan@qutheory.io">Logan Wright</a>,and the hundreds of members of Vapor.</p>
|
|
</main>
|
|
|
|
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
<script src="/1.5/scripts/highlight.pack.js"></script>
|
|
|
|
<script>
|
|
hljs.registerLanguage("leaf", function (hljs) {
|
|
/* Author: Hale Chan <halechan@qq.com> */
|
|
return {
|
|
c: [
|
|
{
|
|
cN: 'function',
|
|
b: '#+',
|
|
e: '[)] ',
|
|
rB: true,
|
|
eE: false,
|
|
c : [
|
|
{
|
|
b: '[(]',
|
|
e: '[)]',
|
|
eE: true,
|
|
c: [
|
|
{
|
|
cN: 'string',
|
|
b: '"',
|
|
e: '"'
|
|
},
|
|
{
|
|
cN: 'title',
|
|
b: '[A-Za-z_][A-Za-z_0-9]*'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
cN: 'keyword',
|
|
b: '#+([A-Za-z$_][0-9A-Za-z$_]*)?',
|
|
eP: true
|
|
},
|
|
]
|
|
}
|
|
]
|
|
};
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$(function() {
|
|
// Syntax highlighting
|
|
hljs.initHighlightingOnLoad();
|
|
|
|
if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
|
|
$('body').addClass('safari');
|
|
}
|
|
|
|
$('h1, h2, h3, h4, h5, h6').each(function(key, item) {
|
|
var $item = $(item);
|
|
var id = $item.attr('id');
|
|
if (id) {
|
|
var link = $('<a>');
|
|
link.attr('href', '#' + id);
|
|
$item.wrap(link);
|
|
}
|
|
})
|
|
|
|
$('a.toggle').on('click', function(e){
|
|
e.preventDefault();
|
|
console.log('hi');
|
|
var body = $('body');
|
|
if (body.hasClass('toggled')) {
|
|
body.removeClass('toggled');
|
|
} else {
|
|
body.addClass('toggled');
|
|
}
|
|
})
|
|
|
|
var lastScroll = 0;
|
|
var isUp = false;
|
|
var win = $(window);
|
|
|
|
win.on('scroll', function(){
|
|
var scrollTop = win.scrollTop();
|
|
var scrollBottom = win.scrollTop() + win.height();
|
|
var docHeight = $(document).height();
|
|
|
|
if ( scrollTop < 0 || scrollBottom >= docHeight ){
|
|
return;
|
|
}
|
|
|
|
if (scrollTop > (lastScroll + 0) && scrollTop >= 0) {
|
|
if (!isUp) {
|
|
$('a.toggle.show').addClass('hide')
|
|
}
|
|
isUp = true;
|
|
lastScroll = scrollTop;
|
|
} else if (scrollTop < (lastScroll - 0)) {
|
|
if (isUp) {
|
|
$('a.toggle.show').removeClass('hide')
|
|
}
|
|
isUp = false;
|
|
lastScroll = scrollTop;
|
|
}
|
|
});
|
|
|
|
// scroll to the active nav item
|
|
$("nav .scroll").animate({
|
|
scrollTop: $("nav .active").offset().top - 157
|
|
}, 0);
|
|
|
|
// var lastScrollTop = 0;
|
|
// $(window).scroll(function(event){
|
|
// var st = $(this).scrollTop();
|
|
// if (st > lastScrollTop){
|
|
// $('a.toggle.show').addClass('hide')
|
|
// } else {
|
|
// $('a.toggle.show').removeClass('hide')
|
|
// }
|
|
// lastScrollTop = st;
|
|
// });
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-76177358-4', 'auto');
|
|
ga('send', 'pageview');
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|