Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Perfect framework
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Johnlin
February 02, 2016
Programming
130
1
Share
Perfect framework
讓你在後端也能使用 Swift
Johnlin
February 02, 2016
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
260
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
340
Ruby 型別檢查工具簡介
johnlinvc
0
570
Swift Actor 實作探索
johnlinvc
0
190
用 mruby 來寫跨平台工具
johnlinvc
0
110
Actor model 簡介
johnlinvc
0
230
一起玩 Helm 3
johnlinvc
1
150
為什麼 App 卡卡的
johnlinvc
2
1.3k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
240
Other Decks in Programming
See All in Programming
実用!Hono RPC2026
yodaka
2
240
GitHubCopilotCLIをはじめよう.pdf
htkym
0
210
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
210
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
160
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
0
150
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
5k
実践CRDT
tamadeveloper
0
580
Agentic Elixir
whatyouhide
0
370
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
140
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
2
400
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
140
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Making the Leap to Tech Lead
cromwellryan
135
9.8k
30 Presentation Tips
portentint
PRO
1
280
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
340
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Transcript
Perfect framework John Lin (@johnlinvc)
Perfect framework 由PerfectlySoft 開發的 swift web framework https://github.com/PerfectlySoft/Perfect
特色 • 獨立HTTP server 與 Apache module • Request Router
• 支援 Mustache Template Engine • 資料庫連接器,支援MySQL, PostgreSQL, SQLite, MongoDB
Perfect server 包含3個不同的版本 • Standalone: 可以從CLI 直接執行 • Standalone Mac
App: Mac 的GUI HTTP server • mod_perfect: Apache 2.4 的 FastCGI module
運作原理 1. 自動載入在./PerfectLibraries 裡的任何 .framework 2. 執行module 中的 PerfectServerInit() 來註冊Route
和 template 3. 按照route 或 ./webroot 資料夾中的template 來執行對應的handler
使用方法 1. 下載source 2. 安裝Xcode template 3. 開新workspace 4. 使用template
開新專案 5. 匯入http server 與 Library 6. 設定excutable 7. 開始寫web API
下載Source git clone https://github.com/PerfectlySoft/Perfect.git
安裝 Perfect xcode 範本 mkdir -p ~/Library/Developer/Xcode/Templates/Project\ Templates cp Extras/Xcode
Templates/Perfect/Perfect Server Framework.xctemplate ~/Library/Developer/Xcode/Templates/Project\ Templates/
使用Template 開新專案
專案內容 • PerfectHandler.swift : 主要程式碼 • index.mustache : mustache template
匯入server 與 library 使用workspace 的 add file 功能把 PerfectServer/PerfectServer.xcodeproj 與
PerfectLib/PerfectLib.xcodeproj 都加入workspace中, 再把Perfect link 加進 Link Binary With Libraries清單中
設定Excutable
實作HTTP API Perfect 提供兩種API實作方法,page based 和 request based。 page based:
使用mustache template, 在template 中指定handler request based: 使用Router來指定handler 兩者目前無法混用
註冊page handler
在mustache template中指定handler
實作PageHandler
取得http request param
註冊Request Handler
實作Request handler
下回預告 PerfectObject 讓你在server和client 之間共用Data Class,全自動呼叫HTTP API。
Q&A