Closed rybalkinsd closed 5 years ago
@rybalkinsd I guess the challenge is in how the API should look when we have to deal with different data types in the response. From a high level I guess we could categorise types under :
httpXXX { } .use {
val textContent = text() // returns response textual content
val content = json() // returns response body as json if exists and valid json
}
Thoughts?
m/b it's better to allow interaction without use
(handle on our side)
There are two big cases.
for example Fuel has .responseString { request, response, result -> ... }
API
Here is a reference how http4k acts. Our goal is to analyze their experience and provide the most fluent and easiest DSL as possible
@rybalkinsd I took a look at what Fuel provides. Correct me if I don't understand this. Here's a rough idea.
// Defining this could allow access to the String Content in response
internal fun Response.string() = body()?.string()
val stringResponse = "https://www.yandex.ru/search/?text=iphone".httpGet().string()
I understand this isn't a very DSL based approach, but its allows easier access since the user does not need to be concerned with anything(Request, Response, Result) unlike even what Fuel provides with .responseString { request, response, result -> ... }
.
@gokulchandra looks good for me.
how about asXXX
? it's more common naming pattern in my mind
inline fun Response.asString(): String(?) = body()?.string()
inline fun Response.asJson() ...
The only thing we didn't discuss yet - asStream
, as you mentioned before
I should have Draft PR for this issue over the next 2 days. 👍 We can improve on that.
Please also have a look at my latest commits, there is a bit more developed upload dsl idea together with multipart
Using #82 to work on this.
Response
is rather verbose, especially accessing body content.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