sunbrice / Taylor

A lightweight library/framework for writing HTTP web servers with Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Taylor Version Carthage compatible

Swift 2.0 required. Working with xCode 7.0 GM.

Disclaimer: It is a work in progress, it may break. Use it at your own risk.

Taylor is a library which allows you to create web server applications in Swift

Status

At this moment, Taylor only supports GET, POST and PUT HTTP requests. Better documentation is on the way.

## Hello World

import Taylor

let server = Taylor.Server()

server.get("/") {
    req, res, cb in

    res.bodyString = "Hello, world!"
    cb(.Send(req, res))
}

let port = 3002
do {
   print("Staring server on port: \(port)")
   try server.serveHTTP(port: port, forever: true)
} catch let e {
   print("Server start failed \(e)")
}

Playground

The easiest way to try out Taylor is using a playground.

For this, you need to have Carthage installed in your computer, is what it is used for fetching the dependencies.

$ git clone git@github.com:izqui/Taylor.git -b playground
$ cd taylor/
$ sh setup.sh

And that's it, you should be good to go. Have fun!

Usage

You can use Taylor from the command line using Cocoapods Rome or Carthage as dependency managers.

Carthage

Create a Cartfile:

github "izqui/taylor"

And then run:

$ carthage update
$ xcrun swift -F Carthage/Build/Mac yourfile.swift

CocoaPods Rome

Create a Podfile:

platform :osx, '10.10'

plugin 'cocoapods-rome'

pod 'Taylor'

And then run:

$ pod install
$ xcrun swift -F Rome yourfile.swift

Credits to Ayaka Nonaka's Swift Summit talk for sharing this method for doing Scripting in Swift

Dependencies

Right now Taylor relies on an Objective-C library called CocoaAsyncSocket.

Development

For the development of the Taylor framework we use Carthage for managining dependencies.

To contribute to Taylor, clone the project on your local machine and run:

$ carthage bootstrap

Then you can open Taylor.xcodeproj and start developing.

The reason there is a Mac app inside the project is for testing purposes given that you cannot have frameworks linked with a Command Line application in xCode using Carthage. See here.

Inspiration

About

A lightweight library/framework for writing HTTP web servers with Swift

License:MIT License


Languages

Language:Swift 96.7%Language:Ruby 3.3%