Giter Club home page Giter Club logo

servicekit's Introduction

ServiceKit

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?")
}

service.listen()

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: [
        .target(
            name: "DemoService",
            dependencies: ["ServiceKit"]), // Tell the linker to actually connect our dependency
        .testTarget(
            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!")
}

demo.listen()

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

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

servicekit's People

Contributors

cbaltzer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.