libuv base Swift web HTTP server framework

Related tags

Networking Trevi
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
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
💧 A server-side Swift web framework.

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

Vapor 22.4k Jan 2, 2023
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 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
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
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
A simple GCD based HTTP client and server, written in 'pure' Swift

SwiftyHTTP Note: I'm probably not going to update this any further - If you need a Swift networking toolset for the server side, consider: Macro.swift

Always Right Institute 116 Aug 6, 2022
A very basic proof-of-concept Swift HTTP server that does not require Foundation

Swift Server Introduction This is very rough and basic HTTP server written in Swift without using Foundation. This is partially based on the Swifter r

Cezary Wojcik 55 Apr 27, 2022
A simple HTTP server written in Swift

http4swift http4swift is a tiny HTTP server library for Nest-compatible applications. This project is unstable, and the API might be changed at anytim

Shun Takebayashi 27 Jun 29, 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
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
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
Swift/Obj-C HTTP framework with a focus on REST and JSON

Now Archived and Forked PMHTTP will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PHMT

Postmates Inc. 509 Sep 4, 2022
A Concise HTTP Framework in Swift

NetKit A Concise HTTP Framework in Swift. Requirements NetKit requires Swift 5.0 and Xcode 10.2 Installation CocoaPods You can use CocoaPods to integr

Aziz Uysal 4 Apr 23, 2019
A little and powerful iOS framework for intercepting HTTP/HTTPS Traffic.

A little and powerful iOS framework for intercepting HTTP/HTTPS Traffic.

Proxyman 867 Dec 29, 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 Jan 6, 2023
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