-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Response return type #85
Comments
Something like this:
|
This is already possible. Look #23 and #19, use a SuspendResponseConverter like you did in your example. |
@DatL4g, for some reason
inside:
|
@vovahost because you're not doing it correctly. The converter has to look like this: override suspend fun <RequestType> wrapSuspendResponse(
typeData: TypeData,
requestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,
ktorfit: Ktorfit
): Any {
return try {
// the requestFunction will handle the request itself, no need to call ktorfit.httpClient
val (info, response) = requestFunction()
Response.success(response.body(info))
} catch (e: Throwable) {
Response.error(e)
}
} BTW @Foso any reason we pass the Ktorfit instance here? Seems to be a little confusing |
@DatL4g You were right. What you suggested and your repo helped. Thank you. |
so the demo & Response with Ktorfit can merge into Ktorfit release ? THX @Foso |
Sorry for the very late Answer and thank you for the contribution. With 1.4.0 the Response class is now added |
Is your feature request related to a problem? Please describe.
Add support for
Response
return type similar to Retrofit.Additional context
Currently the supported types are:
We also need this use case:
This will allow us to check the status code and other parameters similar to Retrofit Response:
https://github.com/square/retrofit/blob/fbf1225e28e2094bec35f587b8933748b705d167/retrofit/src/main/java/retrofit2/Response.java
We can also copy these tests: https://github.com/square/retrofit/blob/fbf1225e28e2094bec35f587b8933748b705d167/retrofit/src/test/java/retrofit2/ResponseTest.java
Additional Benefits
Make it easier to migrate from Retrofit by reusing existing
Response<DataType>
return values andResponse
interface api.The text was updated successfully, but these errors were encountered: