Swiftpack.co -  cbaltzer/ServiceKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
📦 Web services in Swift
.package(url: "https://github.com/cbaltzer/ServiceKit.git", from: "0.1.2")


Mac build status Linux build status

ServiceKit is a minimalist foundation for building web services in Swift, micro or otherwise.

A super simple example:

import ServiceKit

let service = Service() { req, res in
  res.write("Sup, nerds?")


Getting Started

Getting up and running is pretty quick. You can use this repo as a reference. Check out the Demo folder and Package.swift.

To see it in action, just clone this repo and do:

swift run 

Basic Setup

To get started on your own, make a folder for your project and start a new Swift Package:

swift package init --name DemoService --type executable

Then, update your Package.swift file. If you're new to Swift this is the main manifest file for your project. Similar to package.json in Node, for example.

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "DemoService",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // This is the magic line. 
        .package(url: "https://github.com/cbaltzer/ServiceKit", from: "0.1.0"),
    targets: [
            name: "DemoService",
            dependencies: ["ServiceKit"]), // Tell the linker to actually connect our dependency
            name: "DemoServiceTests",
            dependencies: ["DemoService"]),

The initializer for your package should have provided a main.swift file. Fill it out with a Hello World sample to make sure everything works:

import ServiceKit

let demo = Service() { req, res in
  res.write("Hi, it works!")


Now finally to launch your new service:

swift run 

Check it out at http://localhost:5000/

Environment Setup

Xcode (Mac)

This is the way to go if you're on a Mac. Installing Xcode from the Mac App Store will include the Swift toolchains.

Editing is also easiest with Xcode:

swift package generate-xcodeproj

VSCode (Mac, Linux, Windows)

Getting a Swift dev environment set up on any platform is made pretty easy with the Remote - Containers extension. This will launch a Docker container with the specified environment, including toolchains and other extensions.

Check out the .devcontainer folder for reference.


Deploying is easiest with Docker. Check out the Dockerfile for a basic example of how the demo service is bundled.


Stars: 1
Last commit: 25 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

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