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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Johnlin
February 02, 2016
Programming
150
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
310
一起玩 Helm 3
johnlinvc
1
230
為什麼 App 卡卡的
johnlinvc
2
1.4k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
310
Other Decks in Programming
See All in Programming
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
180
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
470
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
Ruby から Emacs を操作したい
phigasui
0
120
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
190
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
160
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
110
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
680
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
200
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
Crash Auto Pipelines
veronikapj
1
420
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
370
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
2
530
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
The SEO Collaboration Effect
kristinabergwall1
1
620
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
840
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
The Language of Interfaces
destraynor
162
27k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
530
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.7k
The SEO identity crisis: Don't let AI make you average
varn
0
630
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
990