libuv base Swift web HTTP server framework

Overview

Notice

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

If you want to build or test all projects at Xcode, please check out Trevi-Dev.
Otherwise, you can build Trevi, lime and other packages by using Swift Package manager.
Here are an example and it now runs on Linux.

Hope Trevi interests you.

Comments
  • Add Makefile, implement the StreamWritable

    Add Makefile, implement the StreamWritable

    Changes

    • Add Makefile for building the project
    • Implement the StreamWritable
    • Modify the Buffer initializer

    Examples

    Makefile

    make [ all | Trevi | Lime | build | clean ]
    
    • all: Download the Libuv from the github and compile. Then get Libuv.a for this project.
    • Trevi: Compile the 'Trevi'.
    • Lime: Compile the 'Lime'.
    • build: Compile sources which you wrote.
    • clean: Delete all files created while building.

    Writable Stream

    public class Writer: StreamWritable {
        var data = [Int8]()
    
        override func _write(chunk: Buffer, encoding: NSStringEncoding?, callback: writableCallback) {
            data.appendContentsOf(chunk.data)
            print("Adding: \(NSString(bytes: data, length: data.count, encoding: NSUTF8StringEncoding)!)")
            callback(nil)
        }
    }
    
    func onFinish() {
        print("finish!!")
    }
    
    let writer = Writer()
    writer.on("finish", onFinish)
    
    for item in ["Hello ", "World ", "on ", "SWIFT"] {
        writer.write(item)
    }
    writer.end("...!")
    
    print(NSString(bytes: writer.data, length: writer.data.count, encoding: NSUTF8StringEncoding)!)
    

    Result

    Adding: Hello 
    Adding: Hello World 
    Adding: Hello World on 
    Adding: Hello World on SWIFT
    Adding: Hello World on SWIFT...!
    finish!!
    Hello World on SWIFT...!
    
    opened by zero2hex 0
  • Implement the StreamWritable

    Implement the StreamWritable

    Changes

    • Implement the StreamWritable
    • Modify the Buffer initializer

    Examples

    Writable Stream

    public class Writer: StreamWritable {
        var data = [Int8]()
    
        override func _write(chunk: Buffer, encoding: NSStringEncoding?, callback: writableCallback) {
            data.appendContentsOf(chunk.data)
            print("Adding: \(NSString(bytes: data, length: data.count, encoding: NSUTF8StringEncoding)!)")
            callback(nil)
        }
    }
    
    func onFinish() {
        print("finish!!")
    }
    
    let writer = Writer()
    writer.on("finish", onFinish)
    
    for item in ["Hello ", "World ", "on ", "SWIFT"] {
        writer.write(item)
    }
    writer.end("...!")
    
    print(NSString(bytes: writer.data, length: writer.data.count, encoding: NSUTF8StringEncoding)!)
    

    Result

    Adding: Hello 
    Adding: Hello World 
    Adding: Hello World on 
    Adding: Hello World on SWIFT
    Adding: Hello World on SWIFT...!
    finish!!
    Hello World on SWIFT...!
    
    opened by zero2hex 0
  • Add the Stream classes and the File utilty class.

    Add the Stream classes and the File utilty class.

    Changes

    • Add classes for supporting 'Stream' (StreamReadable, StreamWritable)
    • Add a function 'searchWithRegularExpression' for using regular expression simply.
    • Change the File class formed utility(or helper) into that needs instantiation.
    • Add the libuv libraries and headers.

    Examples

    Readable Stream

    public class Counter: StreamReadable {
        private var _max = 10000
        private var _index = 1
    
        override func _read(n: Int) {
            let i = _index++
            if i > _max {
                push(nil)
            } else {
                push("\(i)")
            }
        }
    }
    
    var cnt = 1
    
    func onData(data: AnyObject) {
        let tmp = data as! Buffer
        print("ondata \(cnt++) : \(tmp.data)")
    }
    
    func onEnd() {
        print("onend.")
    }
    
    let counter = Counter()
    counter.on("data", onData)
    counter.on("end", onEnd)
    
    counter.read()
    

    File reading

    let file = ReadableFile(fileAtPath: path).open()
    var buffer = [UInt8](count: 8, repeatedValue: 0)
    let data = NSMutableData()
    
    while file.status == .Open {
        let result: Int = file.read(&buffer, maxLength: buffer.count)
        data.appendBytes(buffer, length: result)
    }
    
    file.close()
    

    File writing

    let file = WritableFile(fileAtPath: "\(path).swift", option: O_CREAT|O_TRUNC).open()
    file.write(UnsafePointer<UInt8>(code.dataUsingEncoding(NSUTF8StringEncoding)!.bytes), maxLength: code.characters.count)
    

    WARNING

    • Classes related File are not modified with Stream yet.
    opened by zero2hex 0
  • Change the File class and regular expression function

    Change the File class and regular expression function

    Changes

    • Add a function 'searchWithRegularExpression' for using regular expression simply.
    • Change the File class formed utility(or helper) into that needs instantiation.
    • Add the libuv libraries and headers.

    Examples

    File reading

    let file = Readable(fileAtPath: path).open()
    var buffer = [UInt8](count: 8, repeatedValue: 0)
    let data = NSMutableData()
    
    while file.status == .Open {
        let result: Int = file.read(&buffer, maxLength: buffer.count)
        data.appendBytes(buffer, length: result)
    }
    
    file.close()
    

    File writing

    let file = Writable(fileAtPath: "\(path).swift", option: O_CREAT|O_TRUNC).open()
    file.write(UnsafePointer<UInt8>(code.dataUsingEncoding(NSUTF8StringEncoding)!.bytes), maxLength: code.characters.count)
    
    opened by zero2hex 0
  • Considering using libuv instead of GCD.

    Considering using libuv instead of GCD.

    We are considering adding asynchronous event library because swift-corelibs-libdispatch is unstable for linux. In addition, we think libuv library has more powerful functions, and it makes our project advance like these projects (https://github.com/luvit/luvit / https://github.com/JuliaLang/julia).

    opened by tommy-th 0
  • Malfunctioning work module in Trevi/Source

    Malfunctioning work module in Trevi/Source

    Trevi is considering use work module to support multi thread while maintaining a event driven, non-blocking I/O model by Libuv. When stream module try read start, however, tcp read crushes like that nread is more than buffer size with out any errors.

    opened by tommy-th 0
Releases(v0.1.0)
Owner
leeyoseob
leeyoseob
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
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 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
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
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
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
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
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
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
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
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
A light-weight server-side service framework written in the Swift programming language.

Smoke Framework The Smoke Framework is a light-weight server-side service framework written in Swift and using SwiftNIO for its networking layer by de

Amazon 1.4k Dec 22, 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
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