The master branch of this project currently compiles with Swift 3.0 Preview 1 released June 13, 2016 using Swift Package Manager.
Important: On OS X you must set the Xcode command line tools preference as follows:
If you do not do this you will experience compile time errors when using SPM on the command line.
Perfect is an application server for Linux or OS X which provides a framework for developing web and other REST services in the Swift programming language. Its primary focus is on facilitating mobile apps which require backend server software, enabling you to use one language for both front and back ends.
Perfect operates using either its own stand-alone HTTP/HTTPS server or through FastCGI. It provides a system for loading your own Swift based modules at startup and for interfacing those modules with its request/response objects or to the built-in mustache template processing system.
Perfect is built on its own high performance completely asynchronous networking engine with the goal of providing a scalable option for internet services. It supports SSL out of the box and provides a suite of tools which are commonly required by internet servers, such as WebSockets and iOS push notifications, but does not limit your options. Feel free to swap in your own favorite JSON or templating systems, etc.
Ensure you have properly installed a Swift 3.0 toolchain from Swift.org. In the terminal, typing:
should produce something like the following:
Apple Swift version 3.0-dev (LLVM 3863c393d9, Clang d03752fe45, Swift e996f0c248) Target: x86_64-apple-macosx10.9
Perfect relies on Home Brew for installing dependencies on OS X. This is currently limited to OpenSSL. To install Home Brew, in the Terminal, type:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install OpenSSL:
brew install openssl brew link openssl --force
Perfect relies on libcurl and OpenSSL:
sudo apt-get install libcurl-dev openssl
Build Starter Project
The following will clone and build an empty starter project and launch the server on port 8181.
git clone https://github.com/PerfectlySoft/PerfectTemplate.git cd PerfectTemplate swift build .build/debug/PerfectTemplate
You should see the following output:
Starting HTTP server on 0.0.0.0:8181 with document root ./webroot
This means the server is running and waiting for connections. Access http://localhost:8181/ to see the greeting. Hit control-c to terminate the server.
You can view the full source code for PerfectTemplate.
Swift Package Manager can generate an Xcode project which can run the PerfectTemplate server and provide full source code editing and debugging for your project. Enter the following in your terminal:
swift package generate-xcodeproj
Open the generated file "PerfectTemplate.xcodeproj". Ensure that you have selected the executable target and selected it to run on "My Mac". You can now run and debug the server.
Do you require documentation? No problem. Access our reference materials here.
Have you written a Perfect tutorial you would like to share with the rest of the Perfect community? Please share it with us!
If you need troubleshooting support, we’ve got you covered.