An open API service indexing awesome lists of open source software.

https://github.com/artemmey/kontract


https://github.com/artemmey/kontract

Last synced: 10 days ago
JSON representation

Awesome Lists containing this project

README

          

Framework for interaction between Ktor server and Ktor client.

### Usage example

Common code (API contract):
```kotlin
sealed class Api : ApiContract() {

var accessToken by header(HttpHeaders.Authorization)

class Sessions : Api() {
override val path = "/sessions"

fun post(body: SessionsPostIn) = post(body)
}

class Users : Api() {
override val path = "/users"

fun post(body: domain.entity.User) = post(body)

fun put(body: domain.entity.User) = put(body)
}

class User : Api() {
override val path = "/users/current"

fun get() = get()
}
}
```

Server code:
```kotlin
method(Api.Users::post) { postUser(it) }

method(Api.Users::put) { putUser(it) }

method(Api.Sessions::post) { postSession(it) }
```

Client code:
```kotlin
Api.Sessions().post(SessionsPostIn(email, pass)).execute()
.onSuccess { saveSession(it) }
```