Swiftpack.co - nnabeyang/swift-simple-server as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nnabeyang.
nnabeyang/swift-simple-server 0.0.1
A simple HTTP server in pure Swift.
⭐️ 0
🕓 3 weeks ago
.package(url: "https://github.com/nnabeyang/swift-simple-server.git", from: "0.0.1")


A simple HTTP server in pure Swift.


import MimeType
import SimpleServer
import NIOCore
import NIOPosix

loadMimeFile(atPath: "/etc/apache2/mime.types")

let threadPool = NIOThreadPool(numberOfThreads: 6)
defer {
    try! threadPool.syncShutdownGracefully()
let io = NonBlockingFileIO(threadPool: threadPool)
let mux = ServeMux()
mux.handle(pattern: "/", handler: FileHandler(root: Dir(base: "./public", io: io)))
mux.handleFunc(pattern: "/hello/simple-server/") { (w, _) in
    _ = w.write("Hello SimpleServer")
listenAndServe(host: "localhost", port: 3000, responder: mux)

Adding SimpleServer as a Dependency

To use the SimpleServer library in a SwiftPM project, add it to the dependencies for your package:

let package = Package(
    // name, platforms, products, etc.
    dependencies: [
        // other dependencies
        .package(url: "https://github.com/apple/swift-nio.git", from: "2.33.0"),
        .package(url: "https://github.com/nnabeyang/swift-mime-type", from: "0.0.0"),
        .package(url: "https://github.com/nnabeyang/swift-simple-server", from: "0.0.0"),
    targets: [
        .executableTarget(name: "<executable-target-name>", dependencies: [
            // other dependencies
                .product(name: "NIOCore", package: "swift-nio"),
                .product(name: "NIOPosix", package: "swift-nio"),
                .product(name: "MimeType", package: "swift-mime-type"),
                .product(name: "SimpleServer", package: "swift-simple-server"),
        // other targets


swift-simple-server is published under the MIT License, see LICENSE.


Noriaki Watanabe@nnabeyang


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


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