Swiftpack.co - Package - httpswift/swifter

Platform Swift Protocols CocoaPods Carthage Compatible

What is Swifter?

Tiny http server engine written in Swift programming language.


* stable - lands on CocoaPods and others. Supports the latest non-beta XCode and SPM. Stable.

* master - stable branch plus experimental web-framework layer.

* 2.0 - next version of Swifter (async IO). Experimental.

How to start?

let server = HttpServer()
server["/hello"] = { .ok(.htmlBody("You asked for \($0)"))  }

How to load HTML by string?

let server = HttpServer()
server[path] = { request in
    return HttpResponse.ok(.text("<html string>"))

How to share files?

let server = HttpServer()
server["/desktop/:path"] = shareFilesFromDirectory("/Users/me/Desktop")

How to redirect?

let server = HttpServer()
server["/redirect"] = { request in
  return .movedPermanently("http://www.google.com")

How to HTML ?

let server = HttpServer()
server["/my_html"] = scopes { 
  html {
    body {
      h1 { inner = "hello" }

How to WebSockets ?

let server = HttpServer()
server["/websocket-echo"] = websocket(text: { session, text in
}, binary: { session, binary in

CocoaPods? Yes.


pod 'Swifter', '~> 1.4.7'

Carthage? Also yes.

github "httpswift/swifter" ~> 1.4.7

Swift Package Manager.

import PackageDescription

let package = Package(
    name: "MyServer",
    dependencies: [
        .package(url: "https://github.com/httpswift/swifter.git", .upToNextMajor(from: "1.4.7"))


docker run -d -p 9080:9080 -v `pwd`:/Swifter -w /Swifter --name Swifter swift bash -c "swift run"


Stars: 2811
Help us keep the lights on



1.4.7 - Jun 10, 2019


  • A new CHANGELOG.md to keep track of changes in the project. (#385) by @Vkt0r
  • Added Danger and Swiftlint to the project. (#398) by @Vkt0r
  • Added the following to Scopes: manifest, ontouchstart, dataText. (#410) by @apocolipse
  • Added htmlBody(String) to HttpResonse as a compability case for the changed html(String) case. (#410) by @apocolipse


  • An issue causing a crash regarding a thread race condition. (#399) by @Vkt0r

  • An issue in the HttpRouter causing issues to handle routes with overlapping in the tail. (#379, #382) by @Vkt0r

  • Fixes build errors by excluding XC(UI)Test files from regular targets. (#397) by @ChristianSteffens

  • Fixes HttpRequest.path value to be parsed without query parameters. (#404) by @mazyod

  • Fixes the issue of missing Content-Length header item when shareFilesFromDirectory is being used to share files. (#406) by @nichbar


  • Performance: Batch reads of websocket payloads rather than reading byte-by-byte. (#387) by @lynaghk
  • Podspec source_files updated to match source file directory changes. (#400) by @welsonpan
  • Refactor: Use Foundation API for Base64 encoding. (#403) by @mazyod
  • Refactor: Use URLComponents for HttpRequest path and query parameters parsing #404) by @mazyod
  • HttpResponse functions statusCode() and reasonPhrase changed to computed variables instead of functions, and made public (No impact on existing usage as it was previously internal). (#410) by @apocolipse
  • Adjusted the associated type of enum case HttpResponseBody.json from AnyObject to Any to allow Swift dictionaries/arrays without converting to their Objective-C counterparts. (#393) by @edwinveger
  • HttpResponse: html requires now a complete html-string, not only the body-part.
  • Include the CHANGELOG.md and README.md in the Xcode-Project for easy access / changes.


1.4.3 - Sep 26, 2018

1.4.2 - Jul 5, 2018