Fast, light web application server framework for Swift. Trevi uses an event-driven, non-blocking I/O model based on libuv (https://github.com/libuv/libuv).
Trevi refers to node.js core modules and makes Trevi core modules similar to support node.js features. Trevi also hopes that node.js developers easily use and develop Trevi.
If you want to build or test all projects at Xcode, please check out Trevi-Dev.
Otherwise, you can build Trevi, lime and other packages by using Swift Package manager.
Here are an example and it now runs on Linux.
- Handles persistent streams
- No dependencies
- Effective data transfer
- Parsing HTTP message
Trevi works with the latest version of Swift 3.0 or latest Snapshot. You can download Swift binaries on here.
-
Update your local package index first.
$ sudo apt-get update && sudo apt-get upgrade
-
Install Swift dependencies on linux:
$ sudo apt-get install clang libicu-dev
-
Install Swift depending on your platform on the follow link (The latest version are recommended).
-
After installation of Swift, check your PATH environment variable whether Swift binary path is set or not. If it is not set execute below.:
$ export PATH=/path/to/swift/installed/usr/bin:"${PATH}"
More details : 'Linux' on here
-
Install git to clone libuv:
$ sudo apt-get install git
-
Install libuv dependencies on linux:
$ sudo apt-get install autoconf automake make build-essential libtool gcc g++
-
Clone libuv:
$ git clone https://github.com/libuv/libuv.git
-
Install libuv:
$ cd libuv $ sh autogen.sh $ ./configure $ make $ make check $ sudo make install
More details : Build Instructions on libuv
-
Set LD_LIBRARY_PATH environment variable to run executable.
$ export LD_LIBRARY_PATH=/usr/local/lib/:/usr/lib:$LD_LIBRARY_PATH
-
Install Swift depending on your platform on the follow link (The latest version are recommended).
-
After installation of Swift, check your PATH environment variable whether Swift binary path is set or not. If it is not set execute below.:
$ export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
More details : 'Apple Platforms' on here
-
Clone libuv:
$ git clone https://github.com/libuv/libuv.git
-
Install libuv:
$ cd libuv $ sh autogen.sh $ ./configure $ make $ make check $ sudo make install
or using Homebrew:
$ brew install --HEAD libuv
More details : Build Instructions on libuv
-
Set LD_LIBRARY_PATH environment variable to run executable.
$ export LD_LIBRARY_PATH=/usr/local/lib/:/usr/lib:$LD_LIBRARY_PATH
-
Create a new project directory
mkdir HelloTrevi
-
Initialize this project as a new Swift package project
$ cd HelloTrevi $ swift build --init
Now your directory structure under HelloTrevi should look like this :
HelloTrevi ├── Package.swift ├── Sources │ └── main.swift └── Tests └── empty
Note: For more information on the Swift Package Manager, go here
-
Add a dependency of Trevi for your project (Package.swift) :
import PackageDescription let package = Package( name: "HelloTrevi", dependencies: [ .Package(url: "https://github.com/Trevi-Swift/Trevi.git", versions: Version(0,1,0)..<Version(0,2,0)), ] )
-
Import the modules, create and start a HTTPServer in your code (Sources/main.swift) :
import Trevi let server = Http () server.createServer({ (req, res, next) in res.statusCode = 200 res.write("Hello Trevi") res.end() }).listen(8081)
-
Build your application :
-
Mac OS X:
$ swift build -Xcc -fblocks -Xswiftc -I/usr/local/include -Xlinker -L/usr/local/lib
-
Ubuntu:
$ swift build -Xcc -fblocks
-
-
Now run your application:
$ .build/debug/HelloTrevi
Note: May need to set LD_LIBRARY_PATH environment variable to run:
$ export LD_LIBRARY_PATH=/usr/local/lib/:/usr/lib:$LD_LIBRARY_PATH
-
Open your browser at http://localhost:8080
-
Enjoy Trevi!
Trevi follows the semantic versioning scheme. The API change and backwards compatibility rules are those indicated by SemVer.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Copyright 2015 Trevi Community
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.