Swiftpack.co - Package - NozeIO/Noze.io

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 :-)

Github

link
Stars: 296

Dependencies

Used By

Total: 0

Releases

Nozabi Modula - 2019-03-16 14:48:58

Compiles w/ Swift 5 snapshots.

Backwardly Not - 2018-07-25 14:21:02

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.

Leaky Leakage - 2018-03-12 22:26:21

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.

Fantastic Four - 2017-09-30 14:13:49

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)

Big Brother is Watching You - 2017-07-13 12:05:50

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

Lost in Transmission - 2017-03-24 13:37:51

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.

Empty Not - 2017-02-16 13:25:26

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.

Loggy Back - 2017-01-27 15:02:42

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

Callyback Backpipe - 2016-11-04 15:29:12

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

Basic Nozes with an End - Part || - 2016-10-28 15:11:36

  • crasher in end handler
  • some API cleanup

Basic Nozes with an End - 2016-10-28 12:00:05

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

`http_parser_settings` - 2016-08-25 11:58:49

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)

Read this. Read that. Redis! - 2016-07-25 14:48:16

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.

Objective-GCD - 2016-07-05 16:16:12

Fixed Noze.io build on macOS with the Swift 3 Preview 1 included in Xcode 8beta aka Objective-GCD.

Noze.io 0.2.10 Cows - 2016-06-27 17:20:39

Bugfixes and lots of cows!

- 2016-06-16 18:40:21

Added very simple cookie and session middleware. Fixed some bugz.

Linux Swift 0.2.2 Hotfix - 2016-06-16 15:47:00

Hotfix, just fixes a crasher in GCD channel implementation.