Skip to content
forked from Zewo/Zewo

Open source libraries for modern and blazing fast server software.

License

Notifications You must be signed in to change notification settings

nguyenducnhaty/Zewo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zewo

Swift Platform License Slack

Zewo is a set of libraries for server side development. With Zewo you can write your web app, REST API, command line tool, database driver, etc. Our goal is to create an ecosystem around the modules and tools we provide so you can focus on developing your application or library, instead of doing everything from scratch.

Currently, we have around 50+ packages. This list grows very fast so it might be outdated. To be sure just check our organization.

Zewo Packages

External Packages

Documentation

Below we provide a getting started guide. This guide can also be found in our official documentation. The documentation contains more info than this guide and we're adding even more every day.

Getting started

Installation

Before we start we need to install some tools and dependencies. If you already installed just skip them.

OS X

Install Xcode 7.3+

Xcode is apple's software development IDE.

Install Homebrew

Homebrew is a package manager for OS X.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Swiftenv

Swiftenv is a version manager for Swift.

git clone https://github.com/kylef/swiftenv.git ~/.swiftenv

After installing you need to configure your shell.

Bash

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile 
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile

On some platforms, you may need to modify ~/.bashrc instead of ~/.bash_profile.

ZSH

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.zshenv
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.zshenv
echo 'eval "$(swiftenv init -)"' >> ~/.zshenv

Fish

echo 'setenv SWIFTENV_ROOT "$HOME/.swiftenv"' >> ~/.config/fish/config.fish
echo 'setenv PATH "$SWIFTENV_ROOT/bin" $PATH' >> ~/.config/fish/config.fish
echo 'status --is-interactive; and . (swiftenv init -|psub)' >> ~/.config/fish/config.fish

Restart your shell so the changes take effect.

Install Zewo

This brew formula installs all Zewo dependencies.

brew install zewo/tap/zewo

Linux

Install Clang and ICU

sudo apt-get install clang libicu-dev

Install Swiftenv

Swiftenv is a version manager for Swift.

git clone https://github.com/kylef/swiftenv.git ~/.swiftenv

After installing you need to configure your shell.

Bash

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bashrc
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(swiftenv init -)"' >> ~/.bashrc

On some platforms, you may need to modify ~/.bash_profile instead of ~/.bashrc.

ZSH

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.zshenv
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.zshenv
echo 'eval "$(swiftenv init -)"' >> ~/.zshenv

Fish

echo 'setenv SWIFTENV_ROOT "$HOME/.swiftenv"' >> ~/.config/fish/config.fish
echo 'setenv PATH "$SWIFTENV_ROOT/bin" $PATH' >> ~/.config/fish/config.fish
echo 'status --is-interactive; and . (swiftenv init -|psub)' >> ~/.config/fish/config.fish

Restart your shell so the changes take effect.

Install Zewo

echo "deb [trusted=yes] http://apt.zewo.io/deb ./" | sudo tee --append /etc/apt/sources.list
sudo apt-get update
sudo apt-get install zewo

Hello World Web App

To showcase what Zewo can do we'll create a hello world web app.

Configure your project

First we need to create a directory for our app.

mkdir hello && cd hello

Then we install Swift Development Snapshot from February 8, 2016.

swiftenv install DEVELOPMENT-SNAPSHOT-2016-02-08-a
swiftenv local DEVELOPMENT-SNAPSHOT-2016-02-08-a

Now we initialize the project with Swift Package Manager (SPM).

swift build --init

This command will create the basic structure for our app.

.
├── Package.swift
├── Sources
│   └── main.swift
└── Tests

Open Package.swift with your favorite editor and add HTTPServer, Router and LogMiddleware as dependencies.

import PackageDescription

let package = Package(
    name: "hello",
    dependencies: [
        .Package(url: "https://github.com/Zewo/HTTPServer.git", majorVersion: 0, minor: 3),
        .Package(url: "https://github.com/Zewo/Router.git", majorVersion: 0, minor: 3),
        .Package(url: "https://github.com/Zewo/LogMiddleware.git", majorVersion: 0, minor: 3)
    ]
)

Do your magic

Open main.swift and make it look like this:

import HTTPServer
import Router
import LogMiddleware

let log = Log()
let logger = LogMiddleware(log: log)

let router = Router { route in
    route.get("/hello") { _ in
        return Response(body: "hello world")
    }
}

try Server(middleware: logger, responder: router).start()

This code:

  • Creates an HTTP server that listens on port 8080 by default.
  • Configures a router which will route /hello to a responder that responds with "hello world".
  • Mounts a logger middleware on the server that will log every request/response pair to the standard error stream (stderr) by default.

Build and run

Now let's build the app.

swift build

After it compiles, run it.

.build/debug/hello

Now open your favorite browser and go to localhost:8080/hello. You should see hello world in your browser's window. 😊

What's next?

Zewo has a lot of modules, check out our organization for more. You can also take a look at our documentation which is growing every day. If you have any doubts you can reach us at our slack. We're very active and always ready to help.

See also:

Umbrella Package

To make your life easier we provide the Zewo umbrella package which resides in this repository. This package provides the most important modules so you don't have to add all of them one by one.

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/Zewo/Zewo.git", majorVersion: 0, minor: 3)
    ]
)

Contributing

Hey! Like Zewo? Awesome! We could actually really use your help!

Open source isn't just writing code. Zewo could use your help with any of the following:

  • Finding (and reporting!) bugs.
  • New feature suggestions.
  • Answering questions on issues.
  • Documentation improvements.
  • Reviewing pull requests.
  • Helping to manage issue priorities.
  • Fixing bugs/new features.

If any of that sounds cool to you, send a pull request! After a few contributions, we'll add you to the organization team so you can merge pull requests and help steer the ship 🚢

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Issues

Because we have lots of modules we use the main repo (this one) to track all our tasks, bugs, features, etc. using Github issues.

Some of us use ZenHub to manage the issues. Unfortunately ZenHub only supports Google Chrome and Firefox, but looks like they're working on Safari support.

Code

If you want to contribute with code you should use our development tool zewo-dev. It makes it much easier to deal with the multitude of packages we maintain.

Community

Slack

The entire Zewo code base is licensed under MIT. By contributing to Zewo you are contributing to an open and engaged community of brilliant Swift programmers. Join us on Slack to get to know us!

License

Zewo is released under the MIT license. See LICENSE for details.

About

Open source libraries for modern and blazing fast server software.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 70.9%
  • Shell 29.1%