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
Johnlin
February 02, 2016
Programming
1
120
Perfect framework
讓你在後端也能使用 Swift
Johnlin
February 02, 2016
Tweet
Share
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
130
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
260
Ruby 型別檢查工具簡介
johnlinvc
0
460
Swift Actor 實作探索
johnlinvc
0
160
用 mruby 來寫跨平台工具
johnlinvc
0
77
Actor model 簡介
johnlinvc
0
190
一起玩 Helm 3
johnlinvc
1
120
為什麼 App 卡卡的
johnlinvc
2
1.2k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
200
Other Decks in Programming
See All in Programming
PipeCDのプラグイン化で目指すところ
warashi
1
290
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
240
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1.1k
チームのテスト力を総合的に鍛えて品質、スピード、レジリエンスを共立させる/Testing approach that improves quality, speed, and resilience
goyoki
5
1k
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
590
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
240
状態遷移図を書こう / Sequence Chart vs State Diagram
orgachem
PRO
2
170
NPOでのDevinの活用
codeforeveryone
0
870
効率的な開発手段として VRTを活用する
ishkawa
0
150
A full stack side project webapp all in Kotlin (KotlinConf 2025)
dankim
0
130
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
280
フロントエンドのパフォーマンスチューニング
koukimiura
5
1.8k
Featured
See All Featured
Side Projects
sachag
455
42k
Why Our Code Smells
bkeepers
PRO
336
57k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
970
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Facilitating Awesome Meetings
lara
54
6.5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
740
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
700
A better future with KSS
kneath
238
17k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Docker and Python
trallard
45
3.5k
Bash Introduction
62gerente
613
210k
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