lightningkite / kommunicate

HTTP Requests and Web Sockets for Kotlin Multiplatform
7 stars 1 forks source link

Kommunicate

By Lightning Kite

A library combining coroutines and io so that you can make HTTP requests and use WebSockets!

Discovery Guide

You can do everything through the object HttpClient.

All of those functions can throw:

Some examples:

//Let's grab a list of posts
val posts: String = HttpClient.callString(
    url = "https://jsonplaceholder.typicode.com/posts",
    method = HttpMethod.GET
)

//Let's do a post!
HttpClient.callString(
    url = "https://jsonplaceholder.typicode.com/posts",
    method = HttpMethod.POST,
    body = HttpBody.string(
        contentType = "application/json",
        value = """{ "id":0, "userId":2, "title": "Test Title", "body": "Post's body" }"""
    )
)

KotlinX Serialization

Use this Gist to get extensions for using kotlinx.serialization with Kommunicate.

Be warned that kotlinx.serialization currently has various issues with native and javascript.