A library combining coroutines and io so that you can make HTTP requests and use WebSockets!
You can do everything through the object HttpClient
.
All of those functions can throw:
ConnectionException
when there's an issue with reaching the hostHttpException
if the resulting response is NOT a 2xx response codeSome 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" }"""
)
)
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.