Write Apache modules in Swift - Express.js style!

What's New

Modern Times


Test build against current environments. Seems to work!


Apache 2 Swift4 Swift5 macOS tuxOS Travis

ApacheExpress allows you to quickly write Server Side Swift applications which run as a native module within the Apache Web Server.

TODO: Cleanup the README. mods_expressdemo

A very basic request/response handler:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = ApacheExpress.express(cmd)
  app.server.onRequest { req, res in
    res.writeHead(200, [ "Content-Type": "text/html" ])
    try res.end("<h1>Hello World</h1>")

Connect like reusable middleware:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = ApacheExpress.express(cmd)
  app.use { req, res, next in
    console.info("Request is passing Connect middleware ...")
    res.setHeader("Content-Type", "text/html; charset=utf-8")
  app.use("/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 the Apache Express is about to leave:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = apache.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)

Yes. All that is running within Apache.


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


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

There is an #apacheexpress channel on the Noze.io Slack.


  • Swift Tools 5.0.0
View More Packages from this Author


Last updated: Sun Mar 12 2023 08:38:28 GMT-0500 (GMT-05:00)