Swiftpack.co - Package - IBM-Swift/KituraContracts

Kitura

Docs Build Status - Master macOS Linux Apache 2 Slack Status

KituraContracts

Summary

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.

Getting Started

To use KituraContracts, import the package:

import KituraContracts

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

Example

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.

Community

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

License

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

Github

link
Stars: 3
Help us keep the lights on

Dependencies

Releases

1.0.0 - May 29, 2018

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

0.0.24 - May 16, 2018

  • Revert the relaxing of Codable types (#22)

0.0.23 - May 4, 2018

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

0.0.22 - Apr 17, 2018

  • Update .swift-version to 4.1

0.0.21 - Apr 12, 2018

  • Add missing Bool type to QueryDecoder (#17)