Server-Side Swift : Perfect のサンプルを動かしてみた
Perfectってなに??
2015年11月に発表された、Swift製のサーバサイドフレームワークです。
Perfect is a web server and toolkit for developers using the Swift programming language to build applications and other REST services. It lets developers build using only Swift to program both the client->facing and server-side of their projects. It’s the ideal backbone for cloud and mobile technologies. Developers can be more productive and efficient using Perfect to write less code and work in one >fundamental language for all their needs.
要約すると、開発者はSwiftだけで、これからはクライアントサイドも、サーバサイドも開発できますよ。そう。Perfectを使えばね。
てことです。
ブログサンプルを動かしてみる
こんな感じで、Perfectを使ったサンプルがたくさんあるのですが、その中から今回は、
このブログサンプルを動かしてみます。
手順は、
1. リポジトリをフォーク&クローン
2. ターミナルから swift build を実行
3. ターミナルから ./.build/debug/Perfect-Blog-Mustache を実行
4. ターミナルに [INFO] Starting HTTP server on 0.0.0.0:8181 が表示されていることを確認
5. ブラウザでポート番号 8181 で確認
実行結果はこんな感じになります。
おおー。
ちなみに、テンプレートエンジンにはmustache、DBにはSQLite3 を使用しているみたいです。
Swift Package Manager を使用
ライブラリ管理ツールには、Swift Package Manager というのを使用しているようです。
知らないワードが出てきたので調べてみる
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. The Package Manager is included in Swift 3.0 and above.
Swift のライブラリ管理ツールでは、CocoPodsやCarthageが有名だと思いますが、いづれもmacOSでしか動きません。一方、Swift Package Manager は Ubuntuでも動きます。なので、Perfect に関してはこっちが主流になっていくのかな。
今回は、ただサンプルを動かしてみただけでしたが、Perfectを使って色々作っていこうかなと思いますので、また随時書いていこうと思います〜。