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
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-5.1

Kitura 1.3k Dec 26, 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
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
Swift-multipart-formdata - MultipartFormData: Build multipart/form-data type-safe in Swift

MultipartFormData Build multipart/form-data type-safe in Swift. A result builder

Felix Herrmann 21 Dec 29, 2022
Approov Integration Examples 0 Jan 26, 2022
Swift-flows - Simplistic hot and cold flow-based reactive observer pattern for Swift… ideal for MVVM architectures

SwiftFlows Simplistic hot and cold flow-based reactive observer pattern for Swif

Tyler Suehr 0 Feb 2, 2022
Elegant HTTP Networking in Swift

Alamofire is an HTTP networking library written in Swift. Features Component Libraries Requirements Migration Guides Communication Installation Usage

Alamofire 38.7k Jan 8, 2023
Robust Swift networking for web APIs

Conduit Conduit is a session-based Swift HTTP networking and auth library. Within each session, requests are sent through a serial pipeline before bei

Mindbody 52 Oct 26, 2022
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022
Swift HTTP for Humans

Just is a client-side HTTP library inspired by python-requests - HTTP for Humans. Features Just lets you to the following effortlessly: URL queries cu

Daniel Duan 1.4k Dec 30, 2022
Network abstraction layer written in Swift.

Moya 14.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

Moya 14.4k Jan 1, 2023
Versatile HTTP Networking in Swift

Net is a versatile HTTP networking library written in Swift. ?? Features URL / JSON / Property List Parameter Encoding Upload File / Data / Stream / M

Intelygenz 124 Dec 6, 2022
A type-safe, high-level networking solution for Swift apps

What Type-safe network calls made easy Netswift offers an easy way to perform network calls in a structured and type-safe way. Why Networking in Swift

Dorian Grolaux 23 Apr 27, 2022
OAuth2 framework for macOS and iOS, written in Swift.

OAuth2 OAuth2 frameworks for macOS, iOS and tvOS written in Swift 5.0. ⤵️ Installation ?? Usage ?? Sample macOS app (with data loader examples) ?? Tec

Pascal Pfiffner 1.1k Jan 8, 2023
Swift based OAuth library for iOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

OAuthSwift 3.1k Jan 6, 2023
🏇 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
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 Swift framework for working with emails

Postal is a swift framework providing simple access to common email providers. Example Connect let postal = Postal(configuration: .icloud(login: "myem

Snips 644 Dec 23, 2022
Replacement for Apple's Reachability re-written in Swift with closures

Reachability.swift Reachability.swift is a replacement for Apple's Reachability sample, re-written in Swift with closures. It is compatible with iOS (

Ashley Mills 7.7k Jan 1, 2023