Swiftpack.co - modswift/Apache as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by modswift.
modswift/Apache 0.5.0
A Swift wrapper for CApache. Make Apache GREAT again!
⭐️ 0
🕓 4 years ago
.package(url: "https://github.com/modswift/Apache.git", from: "0.5.0")

Swift Apache

Apache 2 Swift3 Swift4 Swift5 macOS tuxOS

A Swift API for Apache. This wraps the CApache system package and provides Swift convenience on top of that. This package is part of the mod_swift effort.

Apache provides a very low level API towards Apache, for something more convenient, checkout ApacheExpress.

Using the Apache package

NOTE: This requires a mod_swift installation. W/o it, it will fail to built CApache!

If you setup a new module from scratch, use:

swift apache init

Otherwise setup your Package.swift to include Apache:

import PackageDescription

let package = Package(
  name: "MyTool",
	
  dependencies: [
    .Package(url: "[email protected]:modswift/Apache.git", from: "0.5.0"),
  ]
)

Building an Apache module

Simply invoke

swift apache build

This wraps Swift Package Manager to build your package and then produce a proper module which can be loaded into Apache.

To run a test Apache instance, use:

swift apache serve

Access the Apache using: http://localhost:8042/.

Example

Check mods_baredemo for a low level Apache module which uses the APIs of this package.

A simple Apache handler:

func HelloHandler(p: UnsafeMutablePointer<request_rec>?) -> Int32 {
  let req = ApacheRequest(raw: p!)
  guard req.handler == "helloswift" else { return DECLINED }
  req.puts("Hello World!")
  return OK
}

An Apache handler using the database:

func DatabaseHandler(p: UnsafeMutablePointer<request_rec>?) -> Int32 {
  let req = ApacheRequest(raw: p!)
  guard req.handler == "dbswift" else { return DECLINED }
  
  guard let dbd = req.dbdAcquire() else {
    req.puts("Could not access database!")
    return 500
  }
  
  dbd.select("SELECT name, count FROM pets") { (name : String, count : Int?) in
    req.puts("\(name): \(count)\n")
  }

  return OK
}

Apache Configuration for both:

<Location /helloworld>
  SetHandler helloswift
</Location>

<Location /database>
  SetHandler dbswift
  DBDriver   sqlite3
  DBDParams  "absolute-path-to-testdb.sqlite3"
</Location>

Who

mod_swift 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 a #mod_swift channel on the Noze.io Slack.

GitHub

link
Stars: 0
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

Initially
6 years ago

An initial drop of the Apache API module. Doesn't provide much yet, but good enough to do some testing.

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