mirror of https://github.com/vapor/docs.git
|
|
||
|---|---|---|
| .. | ||
| auth | ||
| deploy | ||
| fluent | ||
| getting-started | ||
| guide | ||
| http | ||
| images | ||
| routing | ||
| scripts | ||
| styles | ||
| switch | ||
| template | ||
| testing | ||
| websockets | ||
| contributing.html | ||
| index.html | ||
| readme.es.html | ||
| readme.zh-cn.html | ||
| readme.zh-hant.html | ||
| screenshot.png | ||
readme.zh-hant.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>
<li class="">
<a href="/1.5/switch/3_0.html">
3.0-beta
</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>這是 Vapor 的說明文件, Vapor 是一個可以在 iOS, macOS 及 Ubuntu 上執行的 Web framework,以及其他相關的套件。</p>
<p>Vapor 是一個在 Swift 上很受歡迎的 Web framework。它提供了清楚易用的 API 及許多方便的基礎功能,方便我們用它建立網站或是後台。</p>
<p>我們可以在 <a href="https://github.com/vapor/vapor">Vapor's GitHub</a> 查看原始碼及說明文件。</p>
<p>閱讀 <a href="https://github.com/vapor/documentation/1.5/index.html">English</a></p>
<p>閱讀 <a href="https://github.com/vapor/documentation/1.5/readme.es.html">Spanish</a></p>
<p>閱讀 <a href="https://github.com/vapor/documentation/1.5/readme.zh-cn.html">简体中文</a></p>
<h2 id="">如何閱讀說明文件</h2>
<p>在 <a href="https://github.com/vapor/documentation">GitHub</a> 上瀏覽每個資料夾,特別是 markdown 檔(副檔名為 .md 的檔案)。或是看 <a href="https://vapor.github.io/documentation/">GitHub Pages</a> 上的文件。</p>
<h2 id="-1">套件</h2>
<p>以下是 Vapor 提供的套件及模組(我們也可以直接使用它們,不透過 Vapor。)</p>
<ul>
<li><a href="https://github.com/vapor/vapor">Vapor</a>: Swift 上最常被使用到的 web framework。
<ul>
<li>Auth: 使用者的認證及存續控制(persistance)。</li>
<li>Sessions: 建立在 cookie 機制上安全、短暫的資料儲存。</li>
<li>Cookies: HTTP cookies.</li>
<li>Routing: 可透過變數類型確定(type-safe)的參數設定來設定路徑。</li>
</ul></li>
<li><a href="https://github.com/vapor/fluent">Fluent</a>: 用來操作 SQL 或 NoSQL 資料庫。</li>
<li><a href="https://github.com/vapor/engine">Engine</a>: 傳輸的核心層。
<ul>
<li>HTTP: HTTP 用戶端及主機端。</li>
<li>URI: URI 的分解及組成。</li>
<li>WebSockets: 在一個 TCB 連線中進行雙向的溝通管道。</li>
<li>SMTP: 透過 Sendgrid 及 Gmail 發送郵件。</li>
</ul></li>
<li><a href="https://github.com/vapor/leaf">Leaf</a>: 一種可擴張的樣本語言(extensible templating language)。(譯註: 這可以用來建立使用者介面。)</li>
<li><a href="https://github.com/vapor/json">JSON</a>: 用 <a href="(https://github.com/dantoml/jay)">Jay JSON</a> 解析工具產生Vapor物件。</li>
<li><a href="https://github.com/vapor/console">Console</a>: 用來處理 console 的輸入、輸出及指令的 Swift 工具。</li>
<li><a href="https://github.com/vapor/tls">TLS</a>: 用來處理 CLibreSSL 的新型 TLS 的 Swift 工具。</li>
<li><a href="https://github.com/vapor/crypto">Crypto</a>: 在 LibreSSL 及 Swift 上進行加密的工具。
<ul>
<li>Digests: 無論有沒有認證(authentication)都可以進行雜湊(hash)。</li>
<li>Ciphers: 編碼及解碼。</li>
<li>Random: 安全的隨機性。</li>
<li>BCrypt: 完全用 Swift 實作。</li>
</ul></li>
<li><a href="https://github.com/vapor/node">Node</a>: 可以輕易地進行類型轉換的資料結構。
<ul>
<li><a href="https://github.com/vapor/polymorphic">Polymorphic</a>: 如同 JSON 一般可以輕易取用資料的語法。</li>
<li><a href="https://github.com/vapor/path-indexable">Path Indexable</a>: 如同 JSON 一樣可以用來處理複雜的資料結構。</li>
</ul></li>
<li><a href="https://github.com/vapor/core">Core</a>: 主要的 extension 群,例如: 變數類型的重新命名、在許多地方都會被使用的 function 等。</li>
<li><a href="https://github.com/vapor/socks">Socks</a>: 將 C 語言的 Socket API 包裝成 Swift 語言。</li>
</ul>
<h2 id="-2">可合併使用的套件</h2>
<p>以下是可以和 Vapor 合併運用的套件列表。(譯註:原文裡這裡還有個東西叫 Provider,那是一種 protocol,讓我們可以掛到 Vapor 中如同第三方元件一樣使用。)</p>
<ul>
<li><a href="https://github.com/vapor/mysql">MySQL</a>: 可透過 Swift 操作 MySQL 的套件。
<ul>
<li><a href="https://github.com/vapor/mysql-driver">MySQL Driver</a>: 透過 Fluent 操作 MySQL 的套件。</li>
<li><a href="https://github.com/vapor/mysql-provider">MySQL Provider</a>: 讓 MySQL 可以在 Vapor 上運作的 provider。</li>
</ul></li>
<li><a href="https://github.com/vapor/sqlite">SQLite</a>: 可透過 Swift 操作 SQLite 3 的套件。
<ul>
<li><a href="https://github.com/vapor/sqlite-driver">SQLite Driver</a>: 透迥 Fluent 操作 SQLite 的工具。</li>
<li><a href="https://github.com/vapor/sqlite-provider">SQLite Provider</a>: 讓 SQLite 可以在 Vapor 上運作的 provider。</li>
</ul></li>
<li><a href="https://github.com/vapor/postgresql">PostgreSQL</a>: 用 Swift 操作 PostgreSQL 的工具。
<ul>
<li><a href="https://github.com/vapor/postgresql-driver">PostgreSQL Driver</a>: 用 Fluent 操作 PostgreSQL 的套件。</li>
<li><a href="https://github.com/vapor/postgresql-provider">PostgreSQL Provider</a>: 讓 PostgreSQL 可以運作在 Vapor 上的 provider。</li>
</ul></li>
<li><a href="https://github.com/OpenKitten/MongoKitten">MongoKitten*</a>: 用 Swift 寫的 MongoDB driver。
<ul>
<li><a href="https://github.com/vapor/mongo-driver">Mongo Driver</a>: Fluent 用的 MongoKitten driver。</li>
<li><a href="https://github.com/vapor/mongo-provider">Mongo Provider</a>: Vapor 用的 MongoKitten provider.</li>
<li><a href="https://github.com/OpenKitten/MainecoonVapor">MainecoonVapor</a>: Vapor 的 MongoKitten 物件關聯管理。</li>
</ul></li>
<li><a href="https://github.com/vapor/redbird">Redbird</a>: 遵循原始協定的規格實作出來的 Swift Redis client 端。
<ul>
<li><a href="https://github.com/vapor/redis-provider">Redis Provider</a>: Vapor 的 Redis cache provider。</li>
</ul></li>
<li><a href="https://github.com/vapor/kitura-provider">Kitura Provider</a>: 在 Vapor 中使用 IBM 的 Kitura HTTP Server。</li>
<li><a href="https://github.com/SwiftyBeaver/SwiftyBeaver-Vapor">SwiftyBeaver</a>: 在 Vapor 中使用 SwiftBeaver 的套件。(譯註: 就像強化版的 NSLog() 或 print())</li>
<li><a href="https://github.com/matthijs2704/vapor-apns">APNS</a>: 用來操作 Apple 推播的工具。</li>
<li><a href="https://github.com/mdab121/vapor-fcm">VaporFCM</a>: 用于发送FCM通知的简单库。</li>
<li><a href="https://github.com/siemensikkema/vapor-jwt">JWT</a>: 讓我們可以設定一些規則以取得特定資源的工具。</li>
<li><a href="https://github.com/JustinM1/VaporS3Signer">VaporS3Signer</a>: 用來產生 HTTP request 的 headers 及已經簽證過的 URL,用來 request AWS S3 的 REST API。</li>
<li><a href="https://github.com/jakeheis/Flock">Flock</a>: 自動將 Swift 專案發佈上主機。
<ul>
<li><a href="https://github.com/jakeheis/VaporFlock">VaporFlock</a>: 利用 Flock 發佈 Vapor applications。</li>
</ul></li>
<li><a href="https://github.com/bygri/vapor-forms">VaporForms</a>: 讓我們在處理前端送來的 form request 時可以輕鬆一點的套件。</li>
<li><a href="https://github.com/BrettRToomey/Jobs">Jobs</a>: 在某個特定的時間點執行某些程式碼的套件。</li>
<li><a href="https://github.com/himani93/heimdall">Heimdall</a>: 用來將收到的 http request 記錄到某個檔案的套件,且這個寫好的檔可以用試算表類型(ex: excel, google sheets)的軟體開啟。</li>
</ul>
<h2 id="-3">作者們</h2>
<p><a href="mailto:tanner@qutheory.io">Tanner Nelson</a>, <a href="mailto:logan@qutheory.io">Logan Wright</a>,以及其他上百位 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>