Swiftpack.co - Package - Kitura/KituraContracts


APIDoc Build Status - Master macOS Linux Apache 2 Slack Status



KituraContracts is a library containing type definitions shared by client (e.g. KituraKit) and server (e.g. Kitura) code. These shared type definitions include Codable Closure Aliases, RequestError, QueryEncoder, QueryDecoder, Coder, Identifier Protocol and Extensions to String and Int, which add conformity to the Identifier protocol.


KituraContracts represents the types and protocols that are common to both the Kitura server and KituraKit client side library. If you are using Kitura or KituraKit, your project does not need to depend on KituraContracts explicitly.

Add dependencies

Add the KituraContracts package to the dependencies within your application’s Package.swift file. Substitute "x.x.x" with the latest KituraContracts release.

.package(url: "https://github.com/IBM-Swift/KituraContracts.git", from: "x.x.x")

Add KituraContracts to your target's dependencies:

.target(name: "example", dependencies: ["KituraContracts"]),

Import package

import KituraContracts


This example, shows how to use a shared type definition for RequestError within a router POST method on users. If no errors occurred and you have a User you can respond with the user and pass nil as the RequestError? value. If there has been an error you can respond with an appropriate error and pass nil for the User?.

public struct User: Codable {

router.post("/users") { (user: User, respondWith: (User?, RequestError?) -> Void) in

    if databaseConnectionIsOk {
        respondWith(user, nil)
    } else {
        respondWith(nil, .internalServerError)

Swift version

The 1.x.x releases were tested on macOS and Linux using the Swift 4.1 binaries. Please note that this is the default version of Swift that is included in Xcode 9.3.

API Documentation

For more information visit our API reference.


We love to talk server-side Swift and Kitura. Join our Slack to meet the team!


This library is licensed under Apache 2.0. Full license text is available in LICENSE.


Stars: 11


Used By

Total: 0


1.2.0 - 2019-09-24 09:45:20

  • feat: Support alternate date formats for QueryParams in QueryEncoder and QueryDecoder (#45)
    • For usage examples, see the documentation for the dateEncodingStrategy and dateDecodingStrategy properties of QueryParams.
  • feat: UUID extended to conform to Identifier (#47)

1.1.3 - 2019-06-21 08:52:06

  • Address compilation warnings with Swift 5.1

1.1.2 - 2019-04-04 12:31:53

  • Support Swift 5

1.1.0 - 2018-08-30 10:35:39

  • Feat: BodyDecoder and BodyEncoder protocols (#29)
  • QueryEncoder and QueryDecoder support for encoding to/from Data (#28)

1.0.2 - 2018-07-05 11:24:04

  • fix: Decoding custom types with TypeDecoder (#27)

1.0.1 - 2018-06-25 14:00:33

Added the following behavior for Empty Query Values:

  • Any Optional type (including String?) defaults to nil
  • Non-optional String successfully decodes to ""
  • Non-optional Bool decodes to false
  • All other non-optional types throw a decoding error

1.0.0 - 2018-05-29 15:13:18

  • QueryEncoder/QueryDecoder: Add new protocol Operation and various structs to implement common operations.

0.0.24 - 2018-05-16 10:06:14

  • Revert the relaxing of Codable types (#22)

0.0.23 - 2018-05-04 09:50:26

  • Relax type constraints to Encodable and Decodable (#18)
  • Documentation enhancements (#9)

0.0.22 - 2018-04-17 08:35:54

  • Update .swift-version to 4.1

0.0.21 - 2018-04-12 14:24:07

  • Add missing Bool type to QueryDecoder (#17)

0.0.20 - 2018-03-05 16:44:24

  • Resolves issues with Swift 4.1 (#14)
  • Define type aliases for Codable identifier arrays (#15)