/Taylor

A library for writing HTTP servers with Swift

Primary LanguageObjective-C

Taylor

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

Disclaimer 2: A major refactor is coming after everything learned at Swift Summit.

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.

Demo

You can use Taylor from the command line using Rome or Carthage as dependency managers, or just compiling the Framework within the .xcworkspace

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

#!/usr/bin/env xcrun swift -F Rome

import Taylor

let server = Taylor.Server()
server.addPostRequestHandler(Middleware.requestLogger(println))

server.get("/") {
    request, response, callback in

    response.bodyString  = "Hello World!"

    callback(.Send(request, response))
}

server.startListening(port: 4000, forever: true) {
    result in
    switch result {
    case .Success:
        println("Up and running")
    case .Error(let e):
        println("Server start failed \(e)")
    }
}
chmod +x server.swift
./server.swift

Dependencies

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

Inspiration