Multiplatform coroutine-based HTTP client wrapper for Kotlin

Overview

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 from an HTTPClient (the default one is DefaultHTTPClient or simply HTTP)
  2. Send the request and receive an HTTPResponse, 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, for example, to provide caching or error handling functionality.

Apache adapter is an example of using custom HTTPClient.

You might also like...
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: !-- Pull in as a traditional dependency -- dependency groupIdcom.konghq/groupId artifactIdunire

Kotlin-echo-client - Echo client using Kotlin with Ktor networking library
Kotlin-echo-client - Echo client using Kotlin with Ktor networking library

Overview This repository contains an echo server implemented with Kotlin and kto

기존 post-sample Repository 공부한 기술들로 다시 만들어보기 (MVVM, Hilt, Coroutine/Flow, DataBinding, Retrofit, Moshi, Jetpack)

post-sample-hilt-jetpack 기존 post-sample Repository에서 새로 학습한 부분 도입 기존 코드 변경 (Observe) LiveData - Flow / StateFlow (DI) Dagger2 - Hilt (Asynchronous)

HttpMocker is a simple HTTP mocking library written in Kotlin to quickly and easily handle offline modes in your apps

HttpMocker HttpMocker is a very lightweight Kotlin library that allows to mock HTTP calls relying on either OkHttp or the Ktor client libraries. It ca

Kotlin HTTP requests library. Similar to Python requests.

khttp khttp is a simple library for HTTP requests in Kotlin. It functions similarly to Python's requests module. import khttp.get fun main(args: Arra

The easiest HTTP networking library for Kotlin/Android

Fuel The easiest HTTP networking library for Kotlin/Android. You are looking at the documentation for 2.x.y.. If you are looking for the documentation

 Ktor-Client  this is the client part that uses the Ktor server
Ktor-Client this is the client part that uses the Ktor server

Ktor-Client this is the client part that uses the Ktor server Previews Tech stack & Open source libraries Minimum SDK level 21. Kotlin+ Coroutines + F

Simple kafka client for monitoring topic events. Client has UI powered by Darklaf
Simple kafka client for monitoring topic events. Client has UI powered by Darklaf

kafka-client Simple kafka client for monitoring topic values. How to start $ java -jar kafka-client-1.0.jar How to use specify kafka hosts in config.y

HTTP Server for Android Instrumentation tests

RESTMock REST API mocking made easy. RESTMock is a library working on top of Square's okhttp/MockWebServer. It allows you to specify Hamcrest matchers

Comments
  • Feature Support for SSLContext

    Feature Support for SSLContext

    Hi,

    Thank you for this awesome http client. I noticed that there is no option to pass an instance of SSLContext within the requests. It would be great to have that option as well for https requests which will enable me and other developers to use a custom list of trusted certificates or even provide a custom client certificate as well for mutual authentication. Would that be possible?

    Kinds regards, Hakan

    opened by Hakky54 1
Releases(0.4)
Owner
Egor Zhdan
Egor Zhdan
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

null 13 Sep 30, 2022
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

AndroidAsync AndroidAsync is a low level network protocol library. If you are looking for an easy to use, higher level, Android aware, http request li

Koushik Dutta 7.3k Jan 2, 2023
socket.io client with Coroutine

socket.io client with Coroutine

Heewon 12 Aug 5, 2022
Kotlin DSL http client

Introduction Kotlin DSL http client Features ?? Developers Experience-driven library without verbosity. ?? Native way to use http client in Kotlin. ??

Sergei Rybalkin 461 Dec 13, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

Square 43.4k Jan 5, 2023
A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Square 41k Jan 5, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
An android asynchronous http client built on top of HttpURLConnection.

Versions 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 Version 1.0.6 Description An android asynchronous http client based on HttpURLConnection. Updates U

David 15 Mar 29, 2020