rybalkinsd / kohttp Goto Github PK
View Code? Open in Web Editor NEWKotlin DSL http client
Home Page: https://kohttp.gitbook.io
License: Apache License 2.0
Kotlin DSL http client
Home Page: https://kohttp.gitbook.io
License: Apache License 2.0
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
need to check all the expectations
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?
split into sections:
related to #53
This release is a complete rework for async features and coroutines support.
asyncHttpGet()
vs async { httpGet() }
Call.Factory.suspendCall
extDispatcher
, should we move to IO?At the moment we ignore url( )
parameters.
It would be better if we will add them as a primary source of params.
checklist:
Upload dsl and ext
Url()
Others
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?
Release 0.7.0 brings multiple ways to provide body content type:
header { type }
body(type) { }
body { form { } / json { } }
Todo
httpPost {
header { type 1 }
body(type 2) {
form { } // <-- type 3
}
}
Valid json types include String
, Number
, Boolean
, Null(empty)
, Object
, Array
See the code
Currently Boolean
and Null(empty)
values are not supported.
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.
Too noisy notification about coverage reduction
3.11.0 --> 3.12.0
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
checklist:
upgrade to 5.0
change nexus uploadArchive
task
Define a DSL as an interface for building URL. Based on okhttp3.HttpUrl.Builder
checklist
Create a prototype for kohttp/js
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
Hey. I've noticed that there is a dependency on Jackson. Is it really that necessary to add it to the library just to use it inside of one extension method? Can it be possibly moved to a separate artifact?
Problem with gradle.build.kts
for now https://search.maven.org/artifact/io.github.rybalkinsd/kohttp/0.1.0/jar
contains
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>1.2.60</version>
<scope>test</scope>
</dependency>
blogpost: https://www.jianshu.com/p/9566d361a5a8
very guess: client is not customized according to the load
Allow Android users to use kohttp
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?
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
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:
This is compiling:
body {
body {}
}
Retry interceptor should be configurable.
Please check LogInterceptor
and SignInterceptor
please check: https://stackoverflow.com/questions/37883418/does-okhttpclient-have-a-max-retry-count
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();
}
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.