Skip to content

Commit d895952

Browse files
Documentation Overhaul
Documentation overhaul and changes.
1 parent de85c1a commit d895952

50 files changed

Lines changed: 5495 additions & 1231 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<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>
55
</p>
66

77

88
<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>
2121
</p>
2222

2323
# KituraContracts
@@ -26,9 +26,45 @@
2626

2727
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.
2828

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+
2960
## 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/).
3163

3264
## Community
3365

3466
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)

Sources/KituraContracts/BodyFormat.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,46 @@ import Foundation
3232
in this situation.
3333

3434
### Usage Example: ###
35-
````
35+
````swift
3636
let format = BodyFormat.json
3737
````
3838
*/
3939
public struct BodyFormat: Equatable {
40+
41+
/**
42+
A String value of the type that the body format will be represented in, which is used to ensure that both the left-hand side and the right-hand side are of the same type in the response body.
43+
*/
4044
public let type: String
4145

4246
private init(_ type: String) {
4347
self.type = type
4448
}
45-
49+
50+
/**
51+
This function checks that both the left-hand side and the right-hand side of the response body are of the same type.
52+
*/
4653
public static func == (_ lhs: BodyFormat, _ rhs: BodyFormat) -> Bool {
4754
return lhs.type == rhs.type
4855
}
49-
56+
57+
/**
58+
The JSON representation of the response body.
59+
*/
5060
public static let json = BodyFormat("application/json")
5161
}
5262

5363
/**
5464
An error that may be thrown when a particular instance of `BodyFormat`
55-
is not supported
65+
is not supported.
5666
*/
5767
public struct UnsupportedBodyFormatError: Error {
68+
/**
69+
The format of the body.
70+
*/
5871
public let bodyFormat: BodyFormat
72+
/**
73+
Initialize `UnsupportedBodyFormatError` with the format of the body.
74+
*/
5975
public init(_ bodyFormat: BodyFormat) {
6076
self.bodyFormat = bodyFormat
6177
}

0 commit comments

Comments
 (0)