) coming from and is this something I can change by dsl function to be for example some API context data class that is common for a group of routes?
a
Aleksei Tirman [JB]
04/24/2023, 11:26 AM
What do you want to achieve by passing a different type?
d
Daniel
04/24/2023, 11:33 AM
I would like to use it to store some context common to all the API endpoints under it.
Copy code
route("/api/v1"){
// parse important data common to all api requests and save them as subject
route("/endpoint1") {
head {
val ctx = subject
//do sth with ctx
}
get {
val ctx = subject
//do sth with ctx
}
}
get("/endpoint2") {
val ctx = subject
//do sth with ctx
}
}
a
Aleksei Tirman [JB]
04/24/2023, 11:34 AM
Why can’t you just use a shared variable?
d
Daniel
04/24/2023, 12:01 PM
I am not sure I understand what you mean by that. Can you give me example how would I achieve this?
a
Aleksei Tirman [JB]
04/24/2023, 5:17 PM
I mean something like this:
Copy code
routing {
val ctx = Object()
route("/endpoint1") {
head {
//do sth with ctx
}
get {
//do sth with ctx
}
}
get("/endpoint2") {
//do sth with ctx
}
}
d
Daniel
04/25/2023, 10:44 AM
@Aleksei Tirman [JB] but I would like to access headers and other request-specific params in the context construction (
Object
in your snippet), which is not possible since the receiver of the