A lightweight library for writing HTTP web servers with Swift

Overview

Taylor Version Carthage compatible Slack Status

Disclaimer: Not actively working on it anymore. You can check out some alternatives

Swift 2.0 required. Working with Xcode 7.1.

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 in
    res.bodyString = "Hello, world!"
    return .Send
}

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

More advanced usage instructions coming soon!

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 https://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 Swift library called SwiftSockets.

Development

Join our Slack Slack Status

For the development of the Taylor framework we use Carthage for managing 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

Comments
  • LLVM error in v0.3.0

    LLVM error in v0.3.0

    After fetching the Taylor dependency via CocoaPods or Carthage and running as:

    $ xcrun swift -F Rome test.swift
    LLVM ERROR: Program used external function '__TMaC6Taylor6Server' which could not be resolved!
    

    Currently researching this issue

    opened by izqui 13
  • [Suggestion] Make a Slack/Gitter/whatever

    [Suggestion] Make a Slack/Gitter/whatever

    This would make asking silly questions easier since one would be asking in a more relaxed environment. It's also neat for discussion where you don't want to create a Github issue to reach out to the community.

    opened by Danappelxx 7
  • Proper Capitalisation of Xcode

    Proper Capitalisation of Xcode

    Please fix that capitalisation of Xcode in README.md:

    Swift 2.0 required. Working with xCode 7.1.

    It's a bad first impression if you misspell Xcode...

    opened by thbwd 5
  • Not able to install Taylor framework from Rome- What i am doing wrong ?

    Not able to install Taylor framework from Rome- What i am doing wrong ?

    Installing Taylor framework fails and giving the following error "fatal: repository 'https://github.com/nypisces/Taylor.git/' not found" It seems that taylor github path is wrong...

    PodFile ---Start---- platform :osx, '10.9' platform :ios, '8.0' plugin 'cocoapods-rome'

    pod 'Taylor'

    --End--

    pod install Updating local specs repositories

    CocoaPods 0.39.0.beta.4 is available. To update use: gem install cocoapods --pre [!] This is a test version we'd love you to try.

    For more information see http://blog.cocoapods.org and the CHANGELOG for this version http://git.io/BaH8pQ.

    Analyzing dependencies Downloading dependencies Installing AFNetworking (1.3.4) Installing ISO8601DateFormatterValueTransformer (0.6.1) Installing RKValueTransformers (1.1.2) Installing RestKit (0.25.0) Installing SOCKit (1.1) Installing Taylor (0.1.0)

    [!] Error installing Taylor [!] /usr/bin/git clone https://github.com/nypisces/Taylor.git /var/folders/zx/xkz4mnmj58s52gct0mc2hzbh0000gn/T/d20150909-18579-g54bgr --single-branch --depth 1 --branch 0.1.0

    Cloning into '/var/folders/zx/xkz4mnmj58s52gct0mc2hzbh0000gn/T/d20150909-18579-g54bgr'... remote: Repository not found. fatal: repository 'https://github.com/nypisces/Taylor.git/' not found

    opened by karthikprabhuA 5
  • Changes to schema not tagged to a new release.

    Changes to schema not tagged to a new release.

    This causes both carthage and cocoapods-rome to throw errors when installing the library (at least, in my experience).

    This should also be reflected in the .podspec.

    opened by Danappelxx 4
  • Create iOS Target

    Create iOS Target

    Right now the scheme builds and passes carthage build --no-skip-current with no issues!

    Unfortunately I'm having some strange issues with Xcode on my end, so I can't test if it works in an actual app. Definitely needs some testing before merging.

    opened by Danappelxx 3
  • Implement wildcard (*)

    Implement wildcard (*)

    Needs review.

    Valid statements:

    server.get("/*", ...)
    
    server.get("/*/something", ...)
    
    server.get("/something/*/", ...)
    

    and pretty much anything else involving the wildcard character *.

    I've done some testing on my own but I'm not convinced that it's completely bug-free.

    enhancement 
    opened by Danappelxx 3
  • Argument number mismatch in demo code?

    Argument number mismatch in demo code?

    I'm new to both Swift coding and Taylor, been trying to get the example program to run and I keep getting:

    server.swift:6:2: error: contextual type for closure argument list expects 3 arguments, but 2 were specified
            req, res in
    

    with my code being:

    import Taylor
    
    let server = Taylor.Server()
    
    server.get("/") { 
        req, res in
        res.bodyString = "Hello, world!"
        return .Send
    }
    
    let port = 3000
    do {
        print("Starting server on port: \(port)")
        try server.serveHTTP(port: port, forever: true)
    } catch {
        print("Server start failed \(error)")
    }
    

    Just wondering what I'm doing wrong here, I can't work out what any missing parameter would be from reading the Taylor source code right now.

    opened by simonprickett 2
  • can not run in Xcode 7

    can not run in Xcode 7

    I am new in swift, i cloned this project and import into my Xcode, but it can not run, there are two erros shown, any tips can you help me, thanks advance.

    7b03adc2-e79c-43f2-b020-55a738f0a556
    opened by igordonxiao 2
  • Make HTTPStatus an enum and implement custom error pages

    Make HTTPStatus an enum and implement custom error pages

    Sample code:

    server.errorPage(.NotFound) { req, res in
        res.bodyString = "Sorry, but the page you're looking for doesn't seem to exist!"
        return .Send(req, res)
    }
    
    opened by Danappelxx 1
  • Fix issues #12 & #11

    Fix issues #12 & #11

    In my testing, it still returns a 404 on an incorrect path, but if the last handler is a .Continue, then it doesn't (which seems to be a good thing).

    It also fixes #12 since we can just have all middleware return .Continue and still get the expected results.

    opened by Danappelxx 1
  • Support HTTP requests that are sent in arbitrary number of chunks

    Support HTTP requests that are sent in arbitrary number of chunks

    The current implementation of the SocketServer only supports HTTP requests that are sent in 1 or 2 chunks, with the additional requirement of the "Content-Length" header being fully contained in the first chunk for POST and PUT requests. HTTP requests however can be sent in an arbitrary number of chunks and a server must only process the request, after all headers and the full body was received.

    On a fast localhost connection an additional problem occurs: The current implementation checks if the body was contained in the first chunk, if not, it just calls read() on the socket. But in many cases, the body data is not available on the socket yet, which will result in a socket read error 35 (EAGAIN) and the body data is silently dropped.

    I issues a pull request that should fix the above issues. There are still some memory leaks when handling massive amounts of requests, those should be addressed separately.

    opened by arrizer 1
  • Socket handling

    Socket handling

    I made handling of incoming requests more robust. Especially for clients that are sending HTTP requests in multiple chunks. The socket is now detecting when HTTP headers are finished and also supports sending HTTP bodies in multiple segments. This should also fix problems with large bodies or connections with small MTUs. This should fix issue #48

    opened by arrizer 0
  • Hello, World example doesn't seem to work :(

    Hello, World example doesn't seem to work :(

    The Hello, World example isn't working at all for me.

    my code in app delegate, pasted from the docs: `import Cocoa import Taylor

    @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    
    
    func applicationDidFinishLaunching(aNotification: NSNotification) {
    
        let server = Taylor.Server()
    
        server.get("/") { req, res in
            res.bodyString = "Hello, world!"
            return .Send
        }
    
        let port = 3002
        do {
            print("Starting server on port: \(port)")
            try server.serveHTTP(port: port, forever: true)
        } catch {
            print("Server start failed \(error)")
        }
    }
    

    `

    The error is : Contextual type for closure argument list expects 3 arguments, but 2 were specified. I've tried for quite a while to get the format of the closure correct but to no avail. where can I find a working example so I can start using this?

    opened by jhoughjr 3
  • New here, wanted to chip in with an idea

    New here, wanted to chip in with an idea

    Hi guys,

    I'm just learning Swift at the moment. I'm coming from PHP where I use the framework Laravel a lot and I'm trying to switch to swift because I find the language much more beautiful and because it can be much more performant. And now I found Taylor and I really like it.

    Looking at the source-code of Taylor and specifically the way it uses handlers / middleware I felt inspired to mix your way of doing it with Laravel's way of doing it.

    What if a handler looked like this:

    {
        request, response, next in
    
            // I can do all kinds of things here, before I continue to the next middleware
    
            (request, response) = next(request, response)
    
            // Here I can do things that need to be handled on the way out,
            // after the controller has run so to speak
    
            return (request, response)
    }
    

    IMO, this is a bit cleaner than calling callback(.Continue(request, response)). Now you can choose between "continue" and "send", simply by choosing whether to call next or not.

    And another nice thing about this, I read in #12 that you guys wanted a way to make sure if "Continue" was called last, it would be automatically converted to "Send". Well in this case, that is trivial. All you need to do is add a dummy handler at the end that does nothing but return the request and response immediately.

    This way of doing it implied that request and response are value types, not classes, but I think one can just as easily use classes. In that case it would look like this:

    {
        request, response, next in
    
            // I can do all kinds of things here, before I continue to the next middleware
    
            next(request, response)
    
            // Here I can do things that need to be handled on the way out,
            // after the controller has run so to speak
    }
    

    What do you guys think?

    opened by Evertt 1
  • Any plans to support the new Swift build system?

    Any plans to support the new Swift build system?

    It looks like it would be quite trivial aside from the SwiftSockets dependency. Has the team put any thoughts towards doing this? I'd be happy to help contribute some effort.

    opened by BlakeLucchesi 1
Owner
Jorge Izquierdo
Cofounder @aragon, @aragonone
Jorge Izquierdo
💧 A server-side Swift HTTP web framework.

Vapor is an HTTP web framework for Swift. It provides a beautifully expressive and easy-to-use foundation for your next website, API, or cloud project

Vapor 22.4k Jan 3, 2023
libuv base Swift web HTTP server framework

Notice Trevi now open a Trevi Community. Yoseob/Trevi project split up into respective Trevi, lime, middlewares and sys packages at our community. If

leeyoseob 46 Jan 29, 2022
A Swift web framework and HTTP server.

A Swift Web Framework and HTTP Server Summary Kitura is a web framework and web server that is created for web services written in Swift. For more inf

Kitura 7.6k Dec 27, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
A small, lightweight, embeddable HTTP server for Mac OS X or iOS applications

CocoaHTTPServer CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications. Sometimes developers need an embedde

Robbie Hanson 5.5k Jan 7, 2023
GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in iOS, macOS & tvOS apps.

GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in iOS, macOS & tvOS apps. It was written from scr

Pierre-Olivier Latour 6.3k Dec 27, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Dec 31, 2022
Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Kyle Fuller Archive 397 Oct 30, 2022
HTTP Implementation for Swift on Linux and Mac OS X

Swift HTTP Server Simple HTTP implementation for Swift using POSIX socket API. Running on Mac OS X and Linux. For Mac users: You can install new Swift

Huy 451 Jul 28, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Jan 5, 2023
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation <h5 align="right"><a href="http://demo.swiftexpress.io/">Live ?? server running Demo <img src="https://cdn0.iconfinder.com/data/icons/

Crossroad Labs 850 Dec 2, 2022
Sinatra-like DSL for developing web apps in Swift

Swiftra Swiftra is a library that provides DSLs like Sinatra. System Requirements DEVELOPMENT-SNAPSHOT-2016-02-08-a Example See swiftra-example. impor

Shun Takebayashi 262 Jun 29, 2022
A minimal, fast and unopinionated web framework for Swift

![Fire Image] (http://i.imgur.com/1qR6Nl4.png) Blackfire An extremely fast Swift web framework ?? Getting Started If you're familiar with express.js t

Elliott Minns 908 Dec 2, 2022
A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X

IMPORTANT! We don't see any way how to make web development as great as Ruby on Rails or Django with a very static nature of current Swift. We hope th

Saulius Grigaitis 2k Dec 5, 2022
High Performance (nearly)100% Swift Web server supporting dynamic content.

Dynamo - Dynamic Swift Web Server Starting this project the intention was to code the simplest possible Web Server entirely in Swift. Unfortunately I

John Holdsworth 68 Jul 25, 2022
A Swift Multiplatform Single-threaded Non-blocking Web and Networking Framework

Serverside non-blocking IO in Swift Ask questions in our Slack channel! Lightning (formerly Edge) Node Lightning is an HTTP Server and TCP Client/Serv

SkyLab 316 Oct 6, 2022
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Dec 29, 2022
Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Alsey Coleman Miller 258 Oct 6, 2022