A lightweight library for writing HTTP web servers with Swift

Related tags

Networking Taylor
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 swift client for interacting with NATS servers

SwiftyNats A maintained swift client for interacting with a nats server based on NIO2. Tested with Swift 5.4 on and Swift Version Compatibility: Platf

aus der Technik - Simon & Simon GbR 25 Dec 15, 2022
Http - Demo for Http Layer

http Example To run the example project, clone the repo, and run pod install fro

null 0 Jan 24, 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 Jan 6, 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
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
πŸ“‘ RealHTTP is a lightweight yet powerful client-side HTTP library.

RealHTTP RealHTTP is a lightweight yet powerful client-side HTTP library. Our goal is make an easy to use and effortless http client for Swift. Featur

Immobiliare Labs 233 Jan 7, 2023
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 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
Lightweight, flexible HTTP server framework written in Swift

Hummingbird Lightweight, flexible server framework written in Swift. Hummingbird consists of three main components, the core HTTP server, a minimal we

Hummingbird 245 Dec 30, 2022
FlyingFox - a lightweight HTTP server built using Swift Concurrency

Usage Credits Introduction FlyingFox is a lightweight HTTP server built using Swift Concurrency. The server uses non blocking BSD sockets, handling ea

Simon Whitty 262 Dec 24, 2022
Lightweight lib around NSURLSession to ease HTTP calls

AeroGear iOS HTTP Thin layer to take care of your http requests working with NSURLSession. Project Info License: Apache License, Version 2.0 Build: Co

AeroGear 44 Sep 27, 2022
Super lightweight web framework in Swift based on SWSGI

Ambassador Super lightweight web framework in Swift based on SWSGI Features Super lightweight Easy to use, designed for UI automatic testing API mocki

Envoy 170 Nov 15, 2022
πŸ‡ A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022
An Generic HTTP Request Library For Swift

GRequest An HTTP request library written in Swift. ##Basic Usage Be simple, as it should be: Request("https://api.github.com/repos/lingoer/SwiftyJSON/

Ruoyu Fu 114 Oct 18, 2022
ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

Mubarak Alseif 0 Nov 11, 2021
An awesome Swift HTTP library to rapidly create communication layers with API endpoints

An awesome Swift HTTP library to rapidly create communication layers with API endpoints

Binary Birds 69 Nov 28, 2022
A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning.

FridaHookSwiftAlamofire A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning. δΈ­ζ–‡ζ–‡ζ‘£εŠθΏ‡η¨‹ Features Ca

neilwu 69 Dec 16, 2022
The HTTP library used by the Spotify iOS client

Authentication and back-off logic is a pain, let's do it once and forget about it! This is a library that allows you to centralise this logic and forg

Spotify 625 Nov 20, 2022
A simple, lighweight library for making http requets in iOS

HttpKIT Super simple, super lighweight library for making http requets in IOS. It is a work in progress so PR's are definitelty welcome and highly enc

null 0 Dec 5, 2021