I do the clickety-clackety that make the computer go brrr
bnorm / ktor-retrofit Goto Github PK
View Code? Open in Web Editor NEWTurns a Retrofit service interface into Ktor routing
License: Apache License 2.0
Turns a Retrofit service interface into Ktor routing
License: Apache License 2.0
I do the clickety-clackety that make the computer go brrr
I use Response wrapped response structure everywhere in my services (for error handling) so it looks like:
interface Service {
@GET("string")
suspend fun getAll(): Response<List<String>>
@GET("string/{id}")
suspend fun getSingle(@Path("id") id: Long): Response<String>
}
And then in the ktor-retrofit service implementation, I then return a
return Response.success(myResponseObj)
But for some reason, my responses are not transmitted if implemented this way, here's a snippet of the response when hitting a ktor-retrofit implemented endpoint (logged via HttpLoggingInterceptor):
Vary: Origin
Content-Type: application/json; charset=UTF-8
Connection: keep-alive
transfer-encoding: chunked
{}
<-- END HTTP (2-byte body)
Notice the empty {}
The service is installed as:
routing {
route("/") {
authenticate(AuthLabel) {
retrofitService(service = MyService)
}
The behavior of multiple functions in a service mapping to the same endpoint is currently unknown. Retrofit probably doesn't need to protect against this as there could be multiple forms for the same endpoint on the client side. However, installing multiple handlers for the same endpoint might lead to confusing behavior on the server side and should probably not be allowed.
Right now you only support services that have a single super class
Is there a technical reason for this? I have a branch running it fine without that check and as of Retrofit 2.7 it supports this as well.
Example (this currently crashes)
interface Network: NetworkOne, NetworkTwo
class Services(
networkOne: NetworkOne,
networkTwo: NetworkTwo
) : Network,
NetworkOneby networkOne,
NetworkTwoby networkTwo
retrofitService(service = Services(networkOne, networkTwo))
Or get authention info in ServiceApi
I'd like to use io.ktor.auth
's authentication and just stick the implementation of ktor-retrofit Service inside the authenticate{}
block.
What's the recommended way to do this?
Something like this?
authenticate("myService") {
install(RetrofitService) {
service(service = MyService)
}
}
This doesn't look right and for having multiple services I'll need to do install()
multiple times. What's the right way?
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.