GithubHelp home page GithubHelp logo

rybalkinsd / kohttp Goto Github PK

View Code? Open in Web Editor NEW
477.0 19.0 42.0 9.17 MB

Kotlin DSL http client

Home Page: https://kohttp.gitbook.io

License: Apache License 2.0

Kotlin 100.00%
http-client dsl http-dsl kotlin-dsl kotlin networking

kohttp's People

Contributors

andrewponomarev avatar boxresin avatar bpaxio avatar deviantbadge avatar doyaaaaaken avatar dtropanets avatar gitter-badger avatar gokulchandra avatar golovpavel avatar govorovsky avatar hakky54 avatar ivsivak avatar mejiomah17 avatar mixno373 avatar rybalkinsd avatar shtykh avatar vpondala avatar zsmb13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kohttp's Issues

Release 0.9.0

  • #65 Response ext
  • #91 Retry Interceptor
  • #89 Upload DSL headers (tests with Amazon S3)
  • #81 OkHttp version upgrade

Test body content type

Release 0.7.0 brings multiple ways to provide body content type:

  1. header { type }
  2. body(type) { }
  3. body { form { } / json { } }

Todo

  1. Need to update tests to check request content type
  2. Need a remark in docs for cases when content type is declared with override:
httpPost {
    header { type 1 }
    body(type 2) {
        form { }  // <-- type 3
    }
}

Related to #17 #59

release 0.10.0

This release is a complete rework for async features and coroutines support.

  • implement async POST
  • rename all async methods according to follow kotlin guidelines
  • measure asyncHttpGet() vs async { httpGet() }
  • rethink Call.Factory.suspendCall ext
  • consider usage of Dispatcher, should we move to IO?
  • write a blogpost

Passing a URL instead of URL components

I've got an URL https://domain:4567/path passed to a function, and I want to GET this URL with a certain header set (or a cookie, or a body when POSTing, et cetera):

fun download(url: String)
{
  val (myScheme, myHost, myPort, MyPath) = splitMyUrlSomehow(url)

  val response: Response = httpGet {
      scheme = myScheme
      host = myHost
      port = myPort
      path = myPath

      header {
          "some-header" to "hello there"
      }
  }
}

As far as I've figured out, there is no url var which could be used to just pass a URL. And splitting up my URL to pass its components to httpGet in 4 assignments seems rather cumbersome to me. Did I overlook something?

Allow to pass url() in RequestContext

at the moment the only way to pass url to HttpGetContext (Post also) is

host = url.host
port = url.port
path = url.path
scheme = url.protocol

need to provide a clear ability to replace this declaration with

url = url

or

url { ... }

#71 #77 related

Insert parameters in params DSL from Map

Hi guys, this is probably more a question than a bug. Imagine I have this function:

    override fun get(endpoint: String, params: MutableMap<String, Any>?): Response {

        val response = httpGet {
            host = "https://url-for-my-web-service"
            path = endpoint
            param {
                "token" to token
            }
        }
        return  response;
    }

I need to merge the parameters I get from params and the token parameter. However I do not know how to manipulate the param DSL to do that. Is it possible in the current version?

@DslMarker for narrowing the scope

When we create new, for example, httPost we still access the receivers of the outer lambdas:

httpPost {
    host = "1234"
    port = 3333
    path = "/chat/login"
    body {
        form {
            "name" to "33333"
            host = ""
        }
    }
}

Property host will be equal to "" instead "1234"
It can be solved by @DslMarker annotation

Url Builder DSL

Define a DSL as an interface for building URL. Based on okhttp3.HttpUrl.Builder

Response extension functions

Response is rather verbose, especially accessing body content.

httpXXX { } .use {
        val content = it.body()?.string().asJson()
}

Need to observe other http clients and figure out how dsl approach can serve users for clear response consumption.

Previously EagerResponse was introduced, however it's usage is also rather complex

Fork client with shared thread pool, but different customisation

see OkHttpClient class

Customize your client with newBuilder()

 <p>You can customize a shared OkHttpClient instance with {@link #newBuilder()}. This builds a
 client that shares the same connection pool, thread pools, and configuration. Use the builder
 methods to configure the derived client for a specific purpose.

 <p>This example shows a call with a short 500 millisecond timeout:    {@code

   OkHttpClient eagerClient = client.newBuilder()
       .readTimeout(500, TimeUnit.MILLISECONDS)
       .build();
   Response response = eagerClient.newCall(request).execute();
 }

compile is deprecated

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

The configuration for Gradle throws this. The Documentation is unclear on how to install it and where to add the lines in the build.gradle file.

Parse responses in tests with jackson

Currently most of tests are using only response code to validate results.
The idea is to read postman-echo documentation and check what exactly do we expect in response body. Most of responses are json with

  • cookies
  • headers
  • etc

need to check all the expectations

Question: Integration with Fuel?

There is wonderful Fuel library with very similar syntax and giant amount of improvements. At the moment there is no support for OkHttp but it should be not so hard to implement (just implement Client interface).

So @rybalkinsd maybe it makes sense to just implement OkHttpClient in Fuel library and not to reinvent entire library from scratch?

Scope "Runtime" for dependencies?

I am sure you have good reasons for. But it took me longer than I am willing to admit to figure out why "okhttp3.Response" could not be resolved.

Could you either:

  • change the scope to "compile"
  • change the documentation so that new users will recognize that.

Log Interceptor

Analyse okhttp log interceptor
Figure out how to provide our own with minimal DSL configuration
Try to avoid any dependencies for this case.

From the first view okhttp-logging-interceptor's provides too verbose logs

Async get dsl

Design and implement async get DSL.

Both suspend and async options should be provided.

There are different DSL options
1.

httpGet {
    mode = async
    ...
}
asyncHttpGet {
    ...
}

For more information see how httpGet { } and string extension for asyncHttpGet are implemented

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.