Swiftpack.co - RockfordWei/PerfectIOS as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by RockfordWei.
RockfordWei/PerfectIOS 5.4.5
Swift httpd/web server for iOS especially when mock-up server required in unit test.
⭐️ 1
🕓 5 days ago
iOS macOS linux macOS iOS
.package(url: "https://github.com/RockfordWei/PerfectIOS.git", from: "5.4.5")

PerfectIOS: Server-Side Swift for iOS

Get Involed with Perfect!

Swift 5.6 Platforms macOS | Linux License Apache

Perfect: Server-Side Swift

Perfect is a complete and powerful toolbox, framework, and application server for Linux, iOS, and macOS (OS X). It provides everything a Swift engineer needs for developing lightweight, maintainable, and scalable apps and other REST services entirely in the Swift programming language for both client-facing and server-side applications.

Perfect includes a suite of tools that will enhance your productivity as you use only one programming language to build your apps: Swift. The global development community’s most dynamic and popular server-side toolbox and framework available today, Perfect is the backbone for many live web applications and apps available on iTunes.

This guide is designed for developers at all levels of experience to get Perfect up and running quickly.


PerfectIOS is a lightweight httpd/web server designed for iOS unit test.

First, add PerfectIOS to your project:

    .package(url: "https://github.com/RockfordWei/PerfectIOS", .exact("5.4.0"))

Then, a http server will be available in the unit test:

import PerfectHTTP
import PerfectHTTPServer

import XCTest
@testable import PerfectIOSExample

final class PerfectIOSExampleTests: XCTestCase {

    var httpServer: HTTPServer.LaunchContext?
    let greetings = "Hello, world!"
    let port = 8181
    let host = "localhost"
    func handler(request: HTTPRequest, response: HTTPResponse) {
        response.setHeader(.contentType, value: "text/plain")
        response.appendBody(string: greetings)

    override func setUpWithError() throws {
        var routes = Routes()
        routes.add(method: .get, uri: "/", handler: handler)
        httpServer = try HTTPServer.launch(wait: false, name: host, port: port, routes: routes)

    override func tearDownWithError() throws {

    func testExample() throws {
        guard let url = URL(string: "http://\(host):\(port)") else {
            XCTFail("invalid url")
        let exp = expectation(description: greetings)
        URLSession.shared.dataTask(with: URLRequest(url: url)) { data, _, error in
            guard let data = data,
                  let text = String(data: data, encoding: .utf8) else {
                XCTFail("invalid response body")
            XCTAssertEqual(text, "Hello, world!")
        wait(for: [exp], timeout: 10)

Access a tutorial to help you get started using Perfect quickly. It includes straightforward examples of how Perfect can be used.


Get started working with Perfect, deploy your apps, and find more detailed help by consulting our reference library.


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