Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Perfect framework
Search
Johnlin
February 02, 2016
Programming
160
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Perfect framework
讓你在後端也能使用 Swift
Johnlin
February 02, 2016
Transcript
21 slides
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
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
430
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
520
Ruby 型別檢查工具簡介
johnlinvc
0
730
Swift Actor 實作探索
johnlinvc
0
260
用 mruby 來寫跨平台工具
johnlinvc
0
180
Actor model 簡介
johnlinvc
0
320
一起玩 Helm 3
johnlinvc
1
230
為什麼 App 卡卡的
johnlinvc
2
1.4k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
320
Other Decks in Programming
See All in Programming
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
300
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
640
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
310
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
940
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
200
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
310
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
6.1k
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
380
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
600
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
450
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
380
So, you think you're a good person
axbom
PRO
2
2.3k
Bash Introduction
62gerente
615
220k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
340
For a Future-Friendly Web
brad_frost
184
11k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
640
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
How GitHub (no longer) Works
holman
316
150k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.3k