Popularity
2.5
Declining
Activity
0.0
Stable
31
2
1

Programming language: Kotlin
License: MIT License
Tags: Http Clients    
Latest version: v0.4

networkinkt alternatives and similar libraries

Based on the "Http Clients" category.
Alternatively, view networkinkt alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of networkinkt or a related project?

Add another 'Http Clients' Library

README

networkinkt Build Status

This is a lightweight HTTP client for Kotlin. It relies on coroutines on both JS & JVM platforms.

Here is a simple GET request:

val text = HTTP.get("http://httpbin.org/status/200").getText() // suspending call

...and a POST request with HTTP headers and body:

val text = HTTP.post("http://httpbin.org/headers",
                     headers = mapOf("MyLibraryHeader" to "networkinkt"),
                     body = "param=value")
               .getText()

See the usage section for more examples.

Getting started

The project uses Gradle to manage dependencies.

Common JVM & JS build.gradle:

allprojects {
    repositories {
        // ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt:$networkinkt_version"
}

yourproject-jvm/build.gradle:

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt-jvm:$networkinkt_version"
}

yourproject-js/build.gradle:

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt-js:$networkinkt_version"
}

You can always check which version is up-to-date on the releases page

Usage

How to make a request:

  1. Obtain an instance of [HTTPRequest](networkinkt-common/src/main/kotlin/com/egorzh/networkinkt/HTTPRequest.kt) from an [HTTPClient](networkinkt-common/src/main/kotlin/com/egorzh/networkinkt/HTTPClient.kt) (the default one is DefaultHTTPClient or simply HTTP)
  2. Send the request and receive an [HTTPResponse](networkinkt-common/src/main/kotlin/com/egorzh/networkinkt/HTTPResponse.kt), which encapsulates the response code and text
  3. Use code and text properties of a response object
import com.egorzh.networkinkt.*

// 1:
val request /* : DefaultHTTPRequest */ = HTTP.get(url = "http://httpbin.org/status/200")

// 2: (from a suspend function or coroutine)
val response /* : DefaultHTTPResponse */ = HTTP.sendRequest(request)

// 3:
val code = response.code
val text = response.text

Customization

You can easily create your own implementations of [HTTPClient](networkinkt-common/src/main/kotlin/com/egorzh/networkinkt/HTTPClient.kt), for example, to provide caching or error handling functionality.

[Apache adapter](networkinkt-adapter-apache/src/main/kotlin/com/egorzh/networkinkt/adapters/apache/apache.kt) is an example of using custom HTTPClient.