Evented I/O streams for Swift

Overview

Noze.io

Swift3 Swift4 Swift5 macOS iOS Linux Travis

"Das Haus das Verrückte macht."

Noze.io is an attempt to carry over the Node.js ideas into pure Swift. It uses libdispatch for event-driven, non-blocking I/O. Noze.io is built around type-safe back-pressure aware pull-streams (using Swift generics) operating on batches of items. Instead of just operating on bytes, operate on batches of Unicode lines or database records or HTML responses or - you get the idea. Be efficient: Stream everything and ßatch.

A focus is to keep the API similar to Node. Not always possible - Swift is not JavaScript - but pretty close. It comes with rechargeables included, Noze.io is self-contained and doesn't require any extra dependencies. It includes modules such as cows, leftpad, express or redis.

Noze.io works in Cocoa environments as well as on Linux. Head over to our Start page for install instructions.

Is it a good idea? You tell us. Not sure, but we think it might be, because: a) While Swift looks very much like JavaScript, it is actually a very high performance statically typed and AOT-compiled language, b) Code often looks better in Swift, mostly due to trailing-closure syntax, c) No monkey patching while still providing extensions. There are cons too.

Shows us some code!

There is a reasonably large collection of simple, focused: Noze.io examples But here you go, the "standard" Node example, a HelloWorld httpd:

import http

http.createServer { req, res in 
  res.writeHead(200, [ "Content-Type": "text/html" ])
  res.end("<h1>Hello World</h1>")
}
.listen(1337)

An echo daemon, just piping the in-end of a socket into its own-out end:

import net

net.createServer { sock in
  sock.write("Welcome to Noze.io!\r\n")
  sock | sock
}
.listen(1337)

More complex stuff including a Todo-MVC backend can be found in the Noze.io examples. Like what you see? Head over to our Start page to get started.

Contact

Hey, we love feedback. Join the mailing list, Slack channel or just drop us an email to tell us why this is crap (or not?).

Supported Swift Versions

OS Swift Xcode Make SPM
macOS 3.0 Xcode 8 👍🏻 👍
macOS 3.1 Xcode 8.3 👍🏻 👍
tuxOS 3.0.2 👍🏻 👍
tuxOS 3.1 👍🏻 👍

With the release of Swift 3 Noze.io drops support for Swift 2.x. If you are still interested in using it with 2.x, the last release is still available in the legacy/swift23 branch on GitHub.

Status

  • We chose the traditional Swift approach: Make something barely usable, though demoable, and release it with a 3.0 version tag. Then hope that the community kicks in and fills open spots. Well kinda. It's pretty good already! 😉

  • It already has leftpad. As well as cows 🐮 !

  • Implements primarily the happy path. Errors will error. Presumably this will improve over time.

  • A huge strength of Node is the npm package environment and the myriads of packages available for it. Or wait, is it? Well, at least we have leftpad included. And we hope that the Swift package environment is going to grow as well.

  • There are tons of open ends in Noze.io. We welcome contributions of all kinds.

Who

Noze.io is brought to you by The Always Right Institute and ZeeZide. We wouldn't be sad if more people would like to join the effort :-)

Comments
  • Draft UDP socket support, inspired by Node's dgram module

    Draft UDP socket support, inspired by Node's dgram module

    Mostly functional UDP socket support.

    Bit rough around the edges, but tests pass on Linux, and the new tests also seem to work on Darwin ("swift test" only, after deleting existing tests which don't work).

    TODO: Updating the Xcode project for new sources and tests.

    opened by lichtblau 5
  • More warnings etc.

    More warnings etc.

    Beware:

    • The two latest commits (at the branch tip -- not unfortunately in the order github shows) change the API, for both readdir and the JSON initializers. Use your own judgment before merging them. Both are in some sense cleanups following the previous commits to fix warnings, but are orthogonal to them. The benefits are arguable. readdir doesn't normally fail; the JSON String isn't usually mutated, etc. So I understand that these "improvements" may not be stellar. YMMV, HTH.

    Tested:

    • on Linux with swift test, 3.0.2 and 3.1
    • on macOS with xcodebuild -scheme "Working Tests" test
    • in the real world: not tested at all yet
    opened by lichtblau 2
  • Swift 3.1

    Swift 3.1

    Port to Swift 3.1 (tested with the swift-3.1-DEVELOPMENT-SNAPSHOT-2017-03-19-a-ubuntu16.10 tarball).

    In this branch:

    • Fixing the build error is a whitespace change... This is the one and only commit that actually matters.
    • Various super important warnings being addressed. Hope this doesn't break anything. Tests pass.
    • Unrelated semicolon change after touching that file...

    Not in this branch:

    • Something about pointer arithmetic remains. Fixable, but I've got more questions than answers about that code.
    • readdir_r is apparently pointless and should be replaced with readdir
    • Warnings in tests could also be addressed.
    • Need to update the dgram copy&paste files similarly.

    There are several ways to quiet down swift on the string interpolation of optionals. I've opted for the "as Optional" instead of ".debugDescription" for no big reason. Both seem roughly equally ugly.

    opened by lichtblau 2
  • Set

    Set "develop" branch as default instead of "master" branch

    Now master branch is default, so for the first time we saw a tree not updated while a month, we were afraid: "is this project alive?"

    But develop branch is living surely. I think it is better.

    opened by makenowjust 2
  • Wrk stress testing

    Wrk stress testing

    Need improvement to handle load, would it be idea to participate the Swift Server API and consider using their HTTP with Node.js HTTP Parser (C language) for better performance than Node.js itself if the team decide to choose that.

    Error output during wrk testing:

    
    wrk -d10 -c100 -t2 http://localhost:1337/
    Running 10s test @ http://localhost:1337/
      2 threads and 100 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency    68.09ms   22.21ms 132.56ms   69.66%
        Req/Sec   370.48     68.96   560.00     65.00%
      7379 requests in 10.01s, 1.50MB read
      Socket errors: connect 0, read 795, write 1, timeout 0
    Requests/sec:    737.34
    Transfer/sec:    152.98KB
    
    opened by proyb6 1
  • Duplicate symbol in release build

    Duplicate symbol in release build

    Debug is working, it could be Xcode 8.0.1 having issue?

    Compile Swift Module 'httpd_helloworld' (1 sources)
    Linking ./.build/release/httpd-helloworld
    duplicate symbol __TMRbBp in:
        /Users/test/Noze.io/Samples/httpd-helloworld/.build/release/fs.build/FileSource.swift.o
        /Users/test/Noze.io/Samples/httpd-helloworld/.build/release/fs.build/FileTarget.swift.o
    duplicate symbol __TMRbBp in:
        /Users/test/Noze.io/Samples/httpd-helloworld/.build/release/fs.build/FileSource.swift.o
        /Users/test/Noze.io/Samples/httpd-helloworld/.build/release/fs.build/GCDChannelBase.swift.o
    ld: 2 duplicate symbols for architecture x86_64
    <unknown>:0: error: build had 1 command failures
    error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/test/Noze.io/Samples/httpd-helloworld/.build/release.yaml
    
    
    opened by proyb6 1
  • Update builtin Freddy

    Update builtin Freddy

    The Freddy embedded in Noze.io is a little outdated. Functionality should be OK, but the API of Freddy changed a little since the fork. We should update the code to be compatible with upstream.

    I have a Freddy fork which builds on Linux over here: https://github.com/helje5/Freddy (untested)

    opened by helje5 0
  • Travis doesn't always fail when build fails

    Travis doesn't always fail when build fails

    E.g.: https://travis-ci.org/NozeIO/Noze.io/jobs/215874965

    Cloning /home/travis/build/NozeIO/Noze.io
    error: The dependency graph could not be satisfied. The package (/home/travis/build/NozeIO/Noze.io) with version tag in range (0.5.0..<0.5.9223372036854775807) is not found. Found tags ([0.3.1337])
    make[1]: Leaving directory `/home/travis/build/NozeIO/Noze.io/Samples'
    The command "make samples" exited with 0.
    

    No idea what is going on here. It says make samples exited with 0 even though we got the error. Is that our fault or is SPM not setting a proper exit code?

    opened by helje5 0
  • Drop #linux-public

    Drop #linux-public

    ... old Linux Swift used to require a lot of public declarations. I think this is not required anymore, at least not if proper clang/go.ld are being used.

    Summary: go through the source code, drop #linux-public tags and try whether everything still works fine. (Note: I may not have tagged everything #linux-public :-)

    opened by helje5 0
  • Use upstream C http_parser

    Use upstream C http_parser

    We'd like to use the upstream C http_parser instead of the C port (performance, stability, etc). This is easy to when using Swift Package Manager (which can compile C targets). But we also want an out-of-the-box Xcode experience.

    Summary: Need to adjust the Xcode project so that the C http_parser can be built as part of it. Needs some module map magic (contributions are welcome :-)

    opened by helje5 0
Releases(0.6.5)
  • 0.6.5(Mar 16, 2019)

  • 0.6.4(Jul 25, 2018)

    This release adds changes to please current builds of Swift 4.2, e.g. as delivered in Xcode 10 beta 4.

    There is only one major change in the API - socket structs like sockaddr_in or addr_in do not carry a custom initialiser anymore. That is a:

    let a = sockaddr_in()
    

    Is not properly initialising the address anymore, instead it just returns a 0-cleared value. Instead, use one of the other convenience initialisers we provide or make, like so:

    let a = sockaddr_in.make()
    

    This affected no user code in Noze.io itself, so you probably won't hit it either.

    Source code(tar.gz)
    Source code(zip)
  • 0.6.2(Mar 12, 2018)

    There was a long time bug in the routing methods (there are 3 ...) which was leaking the next closure (because that was self-referencing and in not all cases cleaning up properly).

    That has been fixed and should be excellent now.

    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Sep 30, 2017)

    Noze.io FF adds support for Xcode 9 and Swift 4.0.

    Noze.io now compiles using both, Swift 3 (3.0, 3.1 and 3.2), as well as Swift 4. The Xcode project still defaults to Swift 3 to support older Xcode installation. Note that Xcode 9 can also compile Swift 3 (known as Swift 3.2, which can be mixed w/ Swift 4).

    On the SPM side Noze.io is compiled as Swift 4 when available, otherwise as Swift 3.

    Two minor enhancements:

    • add QS module from ExExpress
    • add bodyParser.Options.extended (aka use qs instead of query_string to parse query parameters)
    Source code(tar.gz)
    Source code(zip)
  • 0.5.12(Jul 13, 2017)

    Added the Swiftmon/S example, a source rebuild monitor. And associated improvements to Noze.io, like in the fs.watch and child_process.spawn APIs.

    Changes since 0.5.7:

    • modules:
      • events:
        • bugfix in 'once' logging (drop once listeners before emitting)
      • fs:
        • watch
          • support for recursive and directory watchers
          • bugfixes
      • child_process:
        • API changes to kill (default value, return value, etc)
    • samples:
      • Swiftmon/S - a source rebuild monitor
    • Add TCP_NODELAY option for sockets
    • Xcode 9 upgrade checks
    • Swift 3.2
      • drop @_specialize in CryptoSwift fork
      • stat hack (stat uses lstat)
      • types use .self
      • no more (Void)->Void
      • redundant conformance
      • args after varargs need a name
    • Swift 3.1 compile fixes
    Source code(tar.gz)
    Source code(zip)
  • 0.5.7(Mar 24, 2017)

    Annoyed that your TCP packets always arrive in an orderly fashion? Want to bring more risk to your socket communication? Noze.io has you covered.

    Release 0.5.7 adds the new dgram module contributed by @lichtblau. Example UDP echo daemon:

    sock = dgram.createSocket()
    sock
      .onMessage   { (msg, from) in
        sock.send(msg, to: from) // echo back
      }
      .bind(1337)
    

    Also: fixes for new warnings emitted by Swift 3.1, also contributed by @lichtblau.

    Source code(tar.gz)
    Source code(zip)
  • 0.5.6(Feb 16, 2017)

    Small bugfix / upgrade release:

    • Fixed a bug that happened when the middleware stack was empty.
    • Use Swift 3.0.2 in Travis (Xcode 8.2 on macOS)
    • Allow MiddlewareObjects to be directly used in app.get() etc.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.5(Jan 27, 2017)

    Tiny bugfix release. A thing is that the default listen queue size got bumped from 5 to 512.

    • fix source width to be max 80 columns
    • bump listen backlog to 512
    • typos
    • fix makefile build
    • a few more docs
    • drop some Swift 2 legacy
    • make process.platform public
    Source code(tar.gz)
    Source code(zip)
  • 0.5.3(Nov 4, 2016)

    Minor bugfix release.

    streams module:

    • Bugfix: Fix piping of empty Readable's. When a callback based Readable w/o an actual callback (manual push) got piped, it was issuing an EOF push. This would close the pipe. Instead just ignore the read request and wait for the user to push something to the Readable (content or EOF).

    net module:

    • fix bug in capturing errno

    tests:

    • fix setup&compilation of Linux tests
    • fix Freddy tests for Swift 3.0
    • new pipe tests for callback based streams
    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Oct 28, 2016)

  • 0.5.1(Oct 28, 2016)

    Small release which adds some basic-auth support, a bug fix for readable streams and some Swift error support for the builtin promises.

    • use Linux 3.0.1 GMc which fixes SE-2907
    • Add support for throws in promises, directly throw errors in promise callbacks.
    • streams/ReadableStream: emit a nil-onRead before emitting endReadable
    • simple basic-auth module
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Aug 25, 2016)

    Noze.io 0.3.1 is a minor release which just adds two things: a) compatibility with Swift 3 Preview 4 on both macOS & tuxOS and b) use of the new protocol based http_parser port.

    • global changes
      • compat with Swift 3 Preview 4 on tuxOS & macOS
        • ErrorProtocol is now Error (2.x alias provided in core)
        • UnsafePointer changes
        • xyzLiteralConvertible is now ExpressibleByXYZLiteral (2.x alias provided in core)
        • enum cases must be accessed via .
        • operator funcs are static
        • a few more Objective-GCD changes
        • new POSIXErrorCode vs POSIXError
    • http_parser module
      • switched from closure based http_parser to a protocol based http_parser (faster, more consistent with original)
    • http module
      • use protocol based http_parser
    • tests
      • renamed to match what Swift 3 Preview 6 is expecting (still works with older versions)
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Jul 25, 2016)

    Noze.io is getting persistent. The feature of this release is the new Redis client. Includes a todo-list backend example which stores the todos into Redis.

    Also featuring:

    • convert stuff to be more Swift 3 like while maintaining Swift 2 compat
    • Swift 3 Preview 2 adjustments
    • a common protocol for Unix time value structures (time_t, timeval_t, timespec_t)
    • connect.pause middleware
    • bug fixes. and more bug fixes.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.11(Jul 5, 2016)

  • 0.2.10(Jun 27, 2016)

  • 0.2.8(Jun 16, 2016)

  • 0.2.7(Jun 16, 2016)

Owner
The Noze Consortium
Evented I/O streams for Swift
The Noze Consortium
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
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
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 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
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 3, 2023
💧 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 7, 2023
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
Evented I/O streams for Swift

Noze.io "Das Haus das Verrückte macht." Noze.io is an attempt to carry over the Node.js ideas into pure Swift. It uses libdispatch for event-driven, n

The Noze Consortium 305 Oct 14, 2022
Lazy streams in Swift.

Stream This is a Swift microframework providing a lazy Stream<T> type with generic implementations of ==/!= where T: Equatable. Streams are lazily-pop

Antitypical 82 Jan 29, 2022
Streams of values over time

Streams of values over time. Tailored for Swift. ?? Release Roadmap Getting Started Learn about the Core Reactive Primitives in ReactiveSwift, and Bas

null 2.9k Jan 3, 2023
Radio Streams from all over the world. Free and Open.

RadioBrowserKit - The Swift SDK for Radio Browser Radio Streams from all over the world. Free and Open. RadioBrowserKit is a Swift package which lets

Frank Gregor 5 Oct 17, 2022
A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift

A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift. It features a great API and a battle-tested core. Supporting both MongoDB in server and embedded environments.

null 646 Dec 10, 2022
Swift-music - swift-music is a swift package that provides an easy-to-use API for music related developments.

?? swift-music Introduction swift-music is a swift package that provides an easy-to-use API for music related developments. Currently available module

Jin Zhang 4 Feb 8, 2022
Swift-extensions - Swift package extending the Swift programming language.

swift-extensions A package containing extensions for the Swift programming language. Contribution Reporting a bug If you find a bug, please open a bug

Alexandre H. Saad 2 Jun 12, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.

Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement. Supports Mac OS and Linux Line edit

Andy Best 114 Dec 14, 2022
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class.

MisterFusion MisterFusion makes more easier to use AutoLayout in Swift & Objective-C code. Features Simple And Concise Syntax Use in Swift and Objecti

Taiki Suzuki 316 Nov 17, 2022
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-4.0

Kitura 1.3k Jan 3, 2023