Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perfect framework

Avatar for Johnlin Johnlin
February 02, 2016

Perfect framework

讓你在後端也能使用 Swift

Avatar for Johnlin

Johnlin

February 02, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. 特色 • 獨立HTTP server 與 Apache module • Request Router

    • 支援 Mustache Template Engine • 資料庫連接器,支援MySQL, PostgreSQL, SQLite, MongoDB
  2. Perfect server 包含3個不同的版本 • Standalone: 可以從CLI 直接執行 • Standalone Mac

    App: Mac 的GUI HTTP server • mod_perfect: Apache 2.4 的 FastCGI module
  3. 運作原理 1. 自動載入在./PerfectLibraries 裡的任何 .framework 2. 執行module 中的 PerfectServerInit() 來註冊Route

    和 template 3. 按照route 或 ./webroot 資料夾中的template 來執行對應的handler
  4. 使用方法 1. 下載source 2. 安裝Xcode template 3. 開新workspace 4. 使用template

    開新專案 5. 匯入http server 與 Library 6. 設定excutable 7. 開始寫web API
  5. 安裝 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/
  6. 匯入server 與 library 使用workspace 的 add file 功能把 PerfectServer/PerfectServer.xcodeproj 與

    PerfectLib/PerfectLib.xcodeproj 都加入workspace中, 再把Perfect link 加進 Link Binary With Libraries清單中
  7. 實作HTTP API Perfect 提供兩種API實作方法,page based 和 request based。 page based:

    使用mustache template, 在template 中指定handler request based: 使用Router來指定handler 兩者目前無法混用
  8. Q&A