Kotlin HTTP requests library. Similar to Python requests.

Overview

khttp

Travis CI Codecov VersionEye License Gratipay Documentation status

khttp is a simple library for HTTP requests in Kotlin. It functions similarly to Python's requests module.

import khttp.get

fun main(args: Array<out String>) {
    // Get our IP
    println(get("http://httpbin.org/ip").jsonObject.getString("origin"))
    // Get our IP in a simpler way
    println(get("http://icanhazip.com").text)
}

Dependency

Stable

Stable releases are hosted on JCenter.

<repository>
  <id>jcenter</id>
  <url>https://jcenter.bintray.com/</url>
</repository>
<!-- ... -->
<dependency>
  <groupId>khttp</groupId>
  <artifactId>khttp</artifactId>
  <version>1.0.0</version>
</dependency>

Development

Development builds are currently available through JitPack. Snapshot builds may eventually be hosted on OJO, but are not currently available there.

Comments
  • Added async functionality

    Added async functionality

    This addresses #14 by providing a library implementation of asynchrony using threads and includes a lambda receiver callback mechanism (no promise based approach).

    Usage is as follows:

    khttp.async.get("https://www.google.com/") {
        println("Status Code: $statusCode")
        println("Response Text: $text")
    }
    // OR ...
    khttp.async.get("https://www.google.com/", onError = {
       println("Error message: $message")
    }, onResponse = {
        println("Status Code: $statusCode")
        println("Response Text: $text")
    })
    

    Each original library test is extended to apply to the corresponding async version.

    Hopefully this approach adheres to the core design principles of the library and the provided implementation satisfies all necessary constraints.

    opened by RamV13 11
  • Support for custom SSLContext and Hostname Verifier for ssl configuration

    Support for custom SSLContext and Hostname Verifier for ssl configuration

    Khttp has no supports for client side certificates yet. Providing a sslcontext option within the request parameter will enable the user to use a custom keymanager and trustmanager within the sslcontext. This will enable the user to load x amount of custom key materials and/or x amount of custom trust materials.

    You can use it like this:

    val sslContext: SSLContext = //initialized sslContext
    val hostnameVerifier: HostnameVerifier = //initialized hostnameVerifier
    
    println(get("https://github.com/", sslContext).text)
    
    //or with hostnameVerifier
    println(get("https://github.com/", sslContext, hostnameVerifier).text)
    

    Within the pull requests I also updated all the dependencies and because of that I was also required to do some additional code changes. Please let me know this is ok or if I need to adjust the code a bit more.

    This pull request will close the following feature requests: https://github.com/ascclemens/khttp/issues/64

    opened by Hakky54 6
  • Can't resolve jitpack from Groovy

    Can't resolve jitpack from Groovy

    Unsure if the problem is on my end, or if you didn't pay the monthly JitPack bill, but I can't get this to work:

    @GrabResolver(name='jitpack.io', root='https://jitpack.io')
    @Grab('com.github.jkcclemens:khttp:-SNAPSHOT')
    import khttp
    

    Error:

    unable to resolve class khttp
       @GrabResolver(name='jitpack.io', root='https://jitpack.io/')
       ^
    
    invalid 
    opened by markhu 4
  • 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 a sslcontext and hostname verifier for ssl configuration. It would be great to have that option as well for https requests. Will there also be a support for SSLContext to configure the client?

    Kinds regards, Hakan

    opened by Hakky54 2
  • Implement Bearer Token Authorization

    Implement Bearer Token Authorization

    This commit implements support for bearer token authorization.

    It's a pretty naive implementation, I don't think there's much complexity here. Have added a simple unit test.

    Hope this helps :)

    opened by kiwipom 2
  • please! how to use  send a request to a website with proxys

    please! how to use send a request to a website with proxys

    I want to crawler somethings from other website,and I want to use khttp to do this job,but I do not know how to send a request to a website with proxys

    opened by zhangweilun 2
  • Content-Type is not overridable

    Content-Type is not overridable

    We're writing a client for an API that uses "Content-Type: application/json; charset=utf-8". When we make a khttp.put request with this header, the request headers do not include the charset and instead uses the default header "Content-Type: application/json;" for a json parameter and "Content-Type: text/plain" for data.

    opened by berlin-ab 2
  • Provide .jar artifacts

    Provide .jar artifacts

    I had trouble using JitPack, but those are my problems

    The issue with khttp is that there is nowhere one can download actual compiled .jar for the library.

    For example JCenter provides such an option, so I can use libs hosted there. I believe it is much easier to setup than Maven Central, you should look into it anyway.

    Providing jars for some snapshots right on github is not a bad idea either.

    opened by voddan 2
  • Support for custom SSLContext and Hostname Verifier for ssl configuration

    Support for custom SSLContext and Hostname Verifier for ssl configuration

    Khttp has no supports for client side certificates yet. Providing a sslcontext option within the request parameter will enable the user to use a custom keymanager and trustmanager within the sslcontext. This will enable the user to load x amount of custom key materials and/or x amount of custom trust materials.

    You can use it like this:

    val sslContext: SSLContext = //initialized sslContext
    val hostnameVerifier: HostnameVerifier = //initialized hostnameVerifier
    
    println(get("https://github.com/", sslContext).text)
    
    //or with hostnameVerifier
    println(get("https://github.com/", sslContext, hostnameVerifier).text)
    

    Within the pull requests I also updated all the dependencies and because of that I was also required to do some additional code changes. Please let me know this is ok or if I need to adjust the code a bit more.

    This pull request will close the following feature requests: https://github.com/ascclemens/khttp/issues/64

    opened by Hakky54 1
  • Use on gradle / Android Project Installation

    Use on gradle / Android Project Installation

    It would be nice if you see as part of the installation something like:

    repositories { ... maven { url "https://jitpack.io" } }

    and then you can add the dependencie like:

    dependencies { ... implementation "com.github.jkcclemens:khttp:master-SNAPSHOT" }

    It's very easy but it will save people that want to use it on Android projects some time.

    Regards I really like the project

    enhancement 
    opened by Roquecito 1
  • Support HTTP 307 and HTTP 308 redirects

    Support HTTP 307 and HTTP 308 redirects

    This commit provides support for following HTTP 307 and HTTP 308 redirects. Specifically, the URL.openRedirectingConnection function (located in GenericResponse.kt) was updated to check for the HTTP response code's presence in an array of redirect response codes (301, 302, 303, 307, and 308). Previously, the function was only checking for response codes in the range 301..303.

    For information regarding these additional HTTP status codes, see:

    opened by mb-vsn 1
  • Fix #88 illegal access - 'module java.base does not

    Fix #88 illegal access - 'module java.base does not "opens java.net" to unnamed'

    Fix #88 'Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed'

    opened by OndraZizka 3
  • HTTP Put results in

    HTTP Put results in "Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed"

    khttp version is 1.0.0

    When calling HTTP PUT to a url, i keep getting below error

    java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed module @5f5a92bb
            at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
            at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
            at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
            at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) ~[na:na]
            at khttp.requests.GenericRequest.toIDN(GenericRequest.kt:198) ~[khttp-1.0.0.jar!/:na]
            at khttp.requests.GenericRequest.makeRoute(GenericRequest.kt:208) ~[khttp-1.0.0.jar!/:na]
            at khttp.requests.GenericRequest.<init>(GenericRequest.kt:132) ~[khttp-1.0.0.jar!/:na]
            at khttp.KHttp.request(KHttp.kt:60) ~[khttp-1.0.0.jar!/:na]
            at khttp.KHttp.put(KHttp.kt:55) ~[khttp-1.0.0.jar!/:na]
            at khttp.KHttp.put$default(KHttp.kt:54) ~[khttp-1.0.0.jar!/:na]
            at ai.paravision.mozart.orchestrator.worker.WorkerClient.search$suspendImpl(WorkerClient.kt:29) ~[classes!/:0.0.0]
    
    opened by maheshreddy77 8
  • Is there a maintained alternative solving this problem?

    Is there a maintained alternative solving this problem?

    Is someone aware of alternative to this abandoned project?

    (and yes, noone is obligated to maintain their open source project - but I prefer to use projects which are not dead, and while a bit offtopic it is not like this issue blocks or disturbs development)

    Java is bad at HTTP. Really bad. The tools provided are functionally broken. Unfortunately, by extension, Kotlin is also bad at HTTP. Yet, more and more, the need to interact with APIs and perform basic HTTP requests shows up in programs, but the broken tools in Java make it a big fuss. This isn’t how it should be.

    To combat this, libraries like Unirest have popped up, but they introduce massive amounts of overhead to just make a simple GET request.

    khttp attempts to solve this problem, by mimicking the Python requests module. khttp uses only the org.json.json library and native Java. There’s nothing else. No bullshit.

    from https://khttp.readthedocs.io/en/latest/ is very promising and I am looking exactly for something like this

    opened by matkoniecz 1
  • when using post method, the Content-length is mandatory

    when using post method, the Content-length is mandatory

    Despite providing the Content-length as 0 by headers = mapOf("Content-length" to "0") it still gives the same error that the content length header is required.

    opened by AarshShah33 0
  • Could not get resource 'https://jcenter.bintray.com/khttp/khttp/0.1.0/khttp-0.1.0.pom'. Received status code 502 from server: Bad Gateway

    Could not get resource 'https://jcenter.bintray.com/khttp/khttp/0.1.0/khttp-0.1.0.pom'. Received status code 502 from server: Bad Gateway

    We work in our project with Khttp and toady we have issue get the resource

    Could not resolve khttp:khttp:0.1.0. > Could not get resource 'https://jcenter.bintray.com/khttp/khttp/0.1.0/khttp-0.1.0.pom'. > Could not GET 'https://jcenter.bintray.com/khttp/khttp/0.1.0/khttp-0.1.0.pom'. Received status code 502 from server: Bad Gateway

    Can you update if you know on this? and estimate when it fixed?

    opened by HagiCohn 0
Owner
Anna Clemens
I write code sometimes.
Anna Clemens
super simple library to manage http requests.

HttpAgent super simple library to manage http requests. Gradle dependencies { implementation 'com.studioidan.httpagent:httpagent:1.0.16@aar' } No

idan ben shimon 32 Oct 24, 2021
Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manipulating application data on-the-go.

Pluto Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manip

Mocklets 8 Aug 22, 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
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
Whois4K - A library for who is requests

Whois4K - A library for who is requests

Lyzev 1 Apr 6, 2022
SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network requests with HttpURLConnection.

SimpleApiCalls ?? SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network reque

null 4 Nov 28, 2022
Easily upload files (Multipart/Binary/FTP out of the box) in the background with progress notification. Support for persistent upload requests, customizations and custom plugins.

ℹ️ ?? Get started with 4.x ?? Try it out Get the demo APK Still using 3.x ? It's not maintained or supported. You may have security issues and problem

Alex Gotev 2.7k Jan 3, 2023
A small Android project to practice executing network requests and parsing the network response

InspirationalQuotesExercise A small Android project to practice executing network requests and parsing the network response This app uses the ZenQuote

Caren 0 Oct 13, 2021
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

David Blanc 174 Nov 28, 2022
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

Kittinun Vantasin 4.3k Jan 8, 2023
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jens Klingenberg 637 Dec 25, 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
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

AMIT SHEKHAR 5.5k Dec 27, 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
Java HTTP Request Library

Http Request A simple convenience library for using a HttpURLConnection to make requests and access the response. This library is available under the

Kevin Sawicki 3.3k Jan 6, 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
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 Dec 24, 2022
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

AMIT SHEKHAR 5.5k Jan 3, 2023
Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster.

Volley Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster. For more information about Volley and ho

Google 3.3k Jan 1, 2023