Swiftpack.co - S2Ler/ExpressSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by S2Ler.
S2Ler/ExpressSwift 0.2.0
ExpressJS inspired web server framework on top of Swift NIO.
⭐️ 1
🕓 1 week ago
linux macOS iOS
.package(url: "https://github.com/S2Ler/ExpressSwift.git", from: "0.2.0")


ExpressSwift Linux Build

Swift 5.2, macOS, Linux, ARM64, Raspberry Pi

ExpressJS inspired web server framework on top of Swift NIO.


  • ☐ Error handling


Use SPM.

Sample Package.swift

// swift-tools-version:5.2
import PackageDescription

let package = Package(
  name: "ProjectName",
  products: [
    .executable(name: "ProjectName", targets: ["ProjectName"]),
  dependencies: [
    .package(url: "https://github.com/diejmon/ExpressSwift.git", .upToNextMinor(from: "0.0.1")),
  targets: [
      name: "ProjectName",
      dependencies: [
        .product(name: "ExpressSwift", package: "ExpressSwift"),
  swiftLanguageVersions: [.v5]


import ExpressSwift
import Foundation

var cities: [String] = ["Belarus,Minsk"]
let citiesLock = NSLock()

let express = Express(config: .default)
express.all { _, _ in
  print("Will be called for every request")
  // Means that other route will be able to handle request.
  return true

// Will be called for all requests with uri: server/city and GET.
express.use("/city", .GET) { request, response in
  return false

// :name is a parameter which can be accessed later from request.getParameter
express.use("/city/:name", .POST) { request, response in
  guard let cityName: String = request.getParameter("name") else { return true }
  print("Creating city with name: \(cityName)")
  citiesLock.lock(); defer { citiesLock.unlock() }
  return false

struct Todo: Codable {
  let title: String
  let notes: String

var todos: [Todo] = [Todo(title: "Release ExpressSwift", notes: "git push")]
var todosLock = NSLock()

let todoRouter = Router()
todoRouter.all { (request, response) -> Bool in
  print("Todo router")
  return true

todoRouter.method(.GET) { (request, response) -> Bool in
  return false

todoRouter.method(.POST) { (request, response) -> Bool in
  do {
    let todo = try request.json(Todo.self)
    todosLock.lock(); defer { todosLock.unlock() }
    response.status = .created
  catch {
    response.status = .badRequest
    response.send("Can't decode with error: \(error)")

  return false

// When /todo route is found, the handling will proceed to todoRouter with /todo part substituted from route
express.use("/todo", todoRouter)


Setting up HTTPS server

Provide NIOSSLContext in Express.Config. See HttpsExample


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.


Stars: 1
Last commit: 1 week 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