|
1 | 1 | <p align="center"> |
2 | | - <a href="http://kitura.io/"> |
3 | | - <img src="https://raw.githubusercontent.com/IBM-Swift/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true" height="100" alt="Kitura"> |
4 | | - </a> |
| 2 | +<a href="http://kitura.io/"> |
| 3 | +<img src="https://raw.githubusercontent.com/IBM-Swift/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true" height="100" alt="Kitura"> |
| 4 | +</a> |
5 | 5 | </p> |
6 | 6 |
|
7 | 7 |
|
8 | 8 | <p align="center"> |
9 | | - <a href="http://www.kitura.io/"> |
10 | | - <img src="https://img.shields.io/badge/docs-kitura.io-1FBCE4.svg" alt="Docs"> |
11 | | - </a> |
12 | | - <a href="https://travis-ci.org/IBM-Swift/KituraContracts"> |
13 | | - <img src="https://travis-ci.org/IBM-Swift/KituraContract.svg?branch=master" alt="Build Status - Master"> |
14 | | - </a> |
15 | | - <img src="https://img.shields.io/badge/os-macOS-green.svg?style=flat" alt="macOS"> |
16 | | - <img src="https://img.shields.io/badge/os-linux-green.svg?style=flat" alt="Linux"> |
17 | | - <img src="https://img.shields.io/badge/license-Apache2-blue.svg?style=flat" alt="Apache 2"> |
18 | | - <a href="http://swift-at-ibm-slack.mybluemix.net/"> |
19 | | - <img src="http://swift-at-ibm-slack.mybluemix.net/badge.svg" alt="Slack Status"> |
20 | | - </a> |
| 9 | +<a href="http://www.kitura.io/"> |
| 10 | +<img src="https://img.shields.io/badge/docs-kitura.io-1FBCE4.svg" alt="Docs"> |
| 11 | +</a> |
| 12 | +<a href="https://travis-ci.org/IBM-Swift/KituraContracts"> |
| 13 | +<img src="https://travis-ci.org/IBM-Swift/KituraContracts.svg?branch=master" alt="Build Status - Master"> |
| 14 | +</a> |
| 15 | +<img src="https://img.shields.io/badge/os-macOS-green.svg?style=flat" alt="macOS"> |
| 16 | +<img src="https://img.shields.io/badge/os-linux-green.svg?style=flat" alt="Linux"> |
| 17 | +<img src="https://img.shields.io/badge/license-Apache2-blue.svg?style=flat" alt="Apache 2"> |
| 18 | +<a href="http://swift-at-ibm-slack.mybluemix.net/"> |
| 19 | +<img src="http://swift-at-ibm-slack.mybluemix.net/badge.svg" alt="Slack Status"> |
| 20 | +</a> |
21 | 21 | </p> |
22 | 22 |
|
23 | 23 | # KituraContracts |
|
26 | 26 |
|
27 | 27 | KituraContracts is a library containing type definitions shared by client (e.g. [KituraKit](https://ibm-swift.github.io/KituraKit/)) and server (e.g. [Kitura](https://ibm-swift.github.io/Kitura)) code. These shared type definitions include [Codable Closure Aliases](https://ibm-swift.github.io/KituraContracts/Typealiases.html), [RequestError](https://ibm-swift.github.io/KituraContracts/Structs/RequestError.html), [QueryEncoder](https://ibm-swift.github.io/KituraContracts/Classes/QueryEncoder.html), [QueryDecoder](https://ibm-swift.github.io/KituraContracts/Classes/QueryDecoder.html), [Coder](https://ibm-swift.github.io/KituraContracts/Classes/Coder.html), [Identifier Protocol](https://ibm-swift.github.io/KituraContracts/Protocols/Identifier.html#/s:15KituraContracts10IdentifierP5valueSSv) and [Extensions](https://ibm-swift.github.io/KituraContracts/Extensions.html#/s:SS) to String and Int, which add conformity to the Identifier protocol. |
28 | 28 |
|
| 29 | +## Getting Started |
| 30 | + |
| 31 | +To use KituraContracts, import the package: |
| 32 | + |
| 33 | +````swift |
| 34 | +import KituraContracts |
| 35 | +```` |
| 36 | + |
| 37 | +KituraContracts represents the types and protocols that are common to both the [Kitura](https://github.com/IBM-Swift/Kitura) server and [KituraKit](https://github.com/IBM-Swift/KituraKit) client side library. If using Kitura or KituraKit, your project does not need to depend on KituraContracts explicitly. |
| 38 | + |
| 39 | +## Example |
| 40 | + |
| 41 | +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?`. |
| 42 | + |
| 43 | +````swift |
| 44 | +public struct User: Codable { |
| 45 | + ... |
| 46 | +} |
| 47 | + |
| 48 | +router.post("/users") { (user: User, respondWith: (User?, RequestError?) -> Void) in |
| 49 | + |
| 50 | + if databaseConnectionIsOk { |
| 51 | + ... |
| 52 | + respondWith(user, nil) |
| 53 | + } else { |
| 54 | + ... |
| 55 | + respondWith(nil, .internalServerError) |
| 56 | + } |
| 57 | +} |
| 58 | +```` |
| 59 | + |
29 | 60 | ## Swift version |
30 | | -The 0.0.x releases were tested on macOS and Linux using the Swift 4.0.3 and 4.1 binaries. Please note that this is the default version of Swift that is include in [Xcode 9.2 and 9.3](https://developer.apple.com/xcode/). |
| 61 | + |
| 62 | +The 0.0.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](https://developer.apple.com/xcode/). |
31 | 63 |
|
32 | 64 | ## Community |
33 | 65 |
|
34 | 66 | We love to talk server-side Swift and Kitura. Join our [Slack](http://swift-at-ibm-slack.mybluemix.net/) to meet the team! |
| 67 | + |
| 68 | +## License |
| 69 | + |
| 70 | +This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/IBM-Swift/KituraContracts/blob/master/LICENSE) |
0 commit comments