Swiftpack.co - modswift/ExExpress as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by modswift.
modswift/ExExpress 0.7.2
A simple, synchronous, Express-like web/middleware framework for Swift
⭐️ 6
🕓 1 week ago
.package(url: "https://github.com/modswift/ExExpress.git", from: "0.7.2")


Swift4 Swift5 macOS tuxOS Travis


Checkout the ApacheExpress README. ExExpress is a server-independent Express toolkit for Swift. ApacheExpress is using that by providing the HTTP 'driver' for ExExpress.


TODO: Cleanup the README.

This is what you can do

Fair enough. So we integrated a tiny subset of Noze.io to allow you to do just that. This is what it looks like:

server.onRequest { req, res in
  res.writeHead(200, [ "Content-Type": "text/html" ])
  try res.end("<h1>Hello World</h1>")

Now you are saying, this is all nice and pretty. But what about Connect? I want to write and reuse middleware! Here you go:

let app = server.connect()

app.use { req, res, next in
  console.info("Request is passing Connect middleware ...")
  res.setHeader("Content-Type", "text/html; charset=utf-8")
  // Note: we do not close the request, we continue with the next middleware
  try next()

app.use("/express/connect") { req, res, next in
  try res.write("<p>This is a random cow:</p><pre>")
  try res.write(vaca())
  try res.write("</pre>")

And Express? Sure, the ExExpress is about to leave:

let app = server.express(cookieParser(), session())

app.get("/express/cookies") { req, res, _ in
  // returns all cookies as JSON
  try res.json(req.cookies)

app.get("/express/") { req, res, _ in
  let tagline = arc4random_uniform(UInt32(taglines.count))
  let values : [ String : Any ] = [
    "tagline"     : taglines[Int(tagline)],
    "viewCount"   : req.session["viewCount"] ?? 0,
    "cowOfTheDay" : cows.vaca()
  try res.render("index", values)


ApacheExpress documentation can be found at: docs.apacheexpress.io.


mod_swift, ApacheExpress and ExExpress are brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

There is a #mod_swift channel on the Noze.io Slack.


Stars: 6
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Modern Times
1 week ago

Fixup ExExpress to properly build in current environments.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics