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
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
220
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
320
Ruby 型別檢查工具簡介
johnlinvc
0
540
Swift Actor 實作探索
johnlinvc
0
180
用 mruby 來寫跨平台工具
johnlinvc
0
100
Actor model 簡介
johnlinvc
0
220
一起玩 Helm 3
johnlinvc
1
140
為什麼 App 卡卡的
johnlinvc
2
1.2k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
230
Other Decks in Programming
See All in Programming
Grafana:建立系統全知視角的捷徑
blueswen
0
330
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
Fluid Templating in TYPO3 14
s2b
0
130
Oxlint JS plugins
kazupon
1
810
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
260
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
180
CSC307 Lecture 02
javiergs
PRO
1
770
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Basic Architectures
denyspoltorak
0
660
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
200
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
Typedesign – Prime Four
hannesfritz
42
2.9k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
The Cult of Friendly URLs
andyhume
79
6.8k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
6.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
320
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
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