Skip to content

moski/Taylor

 
 

Repository files navigation

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

About

A library for writing HTTP servers with Swift

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 40.9%
  • CSS 26.5%
  • JavaScript 22.5%
  • Swift 5.2%
  • HTML 4.8%
  • Ruby 0.1%