KamilH
10/14/2020, 8:21 AMHttpClient
? I would like to hide it behind interface for testing and maintainability purposes, but I can’t because its methods are defined as a inline reified
Joost Klitsie
10/14/2020, 8:44 AMHttpResponseValidator
on Javascript? Somehow, if I have this:
HttpResponseValidator {
validateResponse {
check(it.status == HttpStatusCode.OK || it.status == HttpStatusCode.NoContent)
}
handleResponseException {
println("Response exception")
}
}
The handleResponseException is not called, until the coroutine it is launched in cancels. Also subsequent requests are hangingSergey Bezrukov
10/14/2020, 3:19 PMPeter Tran
10/14/2020, 8:00 PMktor-features/ktor-auth
. However, all of the source is under jvm/
. Is there a particular dependency on JVM? Or is there some other reason this cannot be common code and reused on a native platform?Dávid
10/15/2020, 8:46 AMfun Route.authorizedBy(roles: List<String>, callback: Route.() -> Route): Route {
val routeWithRoles = this.createChild(object : RouteSelector(RouteSelectorEvaluation.qualityConstant) {
override fun toString(): String {
return "(roles: $roles)"
}
override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation =
RouteSelectorEvaluation.Constant
})
routeWithRoles.intercept(ApplicationCallPipeline.Call) {
if (!hasAccess(roles, call.user)) {
call.respond(HttpStatusCode.Unauthorized, "Not sufficient authority") //todo I am not sure if I should respond or throw errror
finish() //todo i am not sure if I should call finish here
}
}
callback(routeWithRoles)
return routeWithRoles
}
1. In my code I am uncertain if I should throw an exception from the interceptor or is it ok to call the respond
method?
2. Also is it necessary to call the finish()
there?
3. Should I call proceed()
in the else
branch or is that not necessary?
In general I think it is unclear when to use the proceed and finish methods and what is an intended way to break out of an interceptor with errors.hhariri
than_
10/15/2020, 1:09 PMRodrigo Silva
10/15/2020, 5:02 PMmarios proto
10/16/2020, 11:21 AMsuspend fun get() :Response<DataValue>
in Retrofit would give me a response code, a way to parse an error model returned, etc easily.
How can I have this in Ktor? Haven't seen it in the examples, unless using the HttpResponseValidator
function to the Client configuration, which I will have to configure per api call.
I am pretty sure there is an easier way, but could someone point me to a good example please?Philipp Karlsson
10/16/2020, 12:07 PMput<MyRoute> {
call.respond(HttpStatusCode.OK)
MyService.runTask()
}
This returns the response directly and the synchronous task seems to run until the end.
Does every call already run in a separated thread or do I have to start a new thread for the runTask()?Marc Knaup
10/16/2020, 1:40 PMAli Albaali
10/16/2020, 8:04 PMdorf
10/18/2020, 7:59 AMapplication
variable?
I come from the C# world, and I’m trying to figure out how to actually call suspend functionsrsetkus
10/18/2020, 11:55 AMHttpCache
implementation. Faced with some challenges and some obstacles which I cannot overcome:
1. HttpResponse
and HttpRequest
have few sub-classes but only DefaultHttpResponse
and DefaultHttpRequest
are public but they are annotated as @InternalAPI
. I could use them to deserialize stored data but then it put the project at risk. However, this is not the main issue.
2. Even though, technically DefaultHttpResponse
and DefaultHttpRequest
are usable but they requires HttpClientCall
instance.
3. HttpClientCall
constructor is internal. Function with the same name HttpClientCall
is internal also. So technically cannot create the object instance.
Briefly, HttpClientCall
is main obstacle of implementing permanent cache storage. Does anybody have any idea how to overcome this?John Moore
10/18/2020, 11:44 PMmanlan
10/19/2020, 11:27 AMimplementation("io.ktor:ktor-server-serialization:1.4.1")
I'm still confused about setting up kotlinx #serialization with ktor 😩nikolaymetchev
10/19/2020, 2:23 PMMicrometerMetrics
feature but I don’t see an equivalent one for the ktor client. Am I missing something?Rui
10/19/2020, 3:01 PMlateinit var itemService: ItemService
For now this is what I do, in Order.kt file:
lateinit var itemService: ItemService
fun Route.order() {
post<Order> {
init(...)
}
get<Order> {
init(...)
}
}
init(...) {
itemService = ItemService(...)
}
and in Item.kt file
fun Route.item() {
post<Item> {
init(...)
}
get<Item> {
init(...)
}
}
Basically I put those common objects and their initialization method in one of the routing files, and other routing file can have direct access to those objects and methods.
I wonder what is the more proper way of organizing this? Appreciate any kinds of input !Kris Wong
10/19/2020, 5:37 PMchucvv
10/20/2020, 4:42 AMthan_
10/20/2020, 8:48 AMCachingHeaders
in both, just with different configuration. This fails with io.ktor.application.DuplicateApplicationFeatureException: Conflicting application feature is already installed with the same key
Is this possible at all?John O'Reilly
10/20/2020, 11:41 AMMichael
10/20/2020, 9:42 PMtieskedh
10/21/2020, 10:45 AMKris Wong
10/21/2020, 3:07 PMApplicaiton
after the server is stated?Chris Fillmore
10/21/2020, 4:37 PMAstronaut4449
10/21/2020, 10:20 PMCLOVIS
10/22/2020, 3:30 PMHankG
10/23/2020, 5:14 PMDavide Giuseppe Farella
10/24/2020, 10:54 AMEither
class, similar to the one from Arrow-kt.
I’d like to know if is possible to create a “converter” for it.
Thank you