Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Perfect framework
Search
Johnlin
February 02, 2016
Programming
1
130
Perfect framework
讓你在後端也能使用 Swift
Johnlin
February 02, 2016
Tweet
Share
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
190
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
300
Ruby 型別檢查工具簡介
johnlinvc
0
520
Swift Actor 實作探索
johnlinvc
0
170
用 mruby 來寫跨平台工具
johnlinvc
0
93
Actor model 簡介
johnlinvc
0
200
一起玩 Helm 3
johnlinvc
1
130
為什麼 App 卡卡的
johnlinvc
2
1.2k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
220
Other Decks in Programming
See All in Programming
AWS CDKの推しポイントN選
akihisaikeda
1
240
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.5k
ZOZOにおけるAI活用の現在 ~モバイルアプリ開発でのAI活用状況と事例~
zozotech
PRO
9
5.7k
React Native New Architecture 移行実践報告
taminif
1
160
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
150
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
150
sbt 2
xuwei_k
0
300
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
160
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.9k
認証・認可の基本を学ぼう後編
kouyuume
0
240
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Faster Mobile Websites
deanohume
310
31k
Producing Creativity
orderedlist
PRO
348
40k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Site-Speed That Sticks
csswizardry
13
1k
Docker and Python
trallard
47
3.7k
Fireside Chat
paigeccino
41
3.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
54k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
A Tale of Four Properties
chriscoyier
162
23k
How to train your dragon (web standard)
notwaldorf
97
6.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