is it possible to update the routing on the `Appli...
# ktor
k
is it possible to update the routing on the
Applicaiton
after the server is stated?
j
@John O'Reilly was asking about dynamically enable/disable routes in this channel before. Is this something that could meet your requirements?
j
k
no. I would prefer to design my API to add routes after the
ApplicationEngine
is started. however, I can adapt my API if that does not work properly.
I see that the APIs exist to add routes, but not sure what the expectation is
j
If we assume the server will send the request through a pipeline to see if it matches or not the defined routes, defining the routes anyway and flag them enabled/disabled (returning 404 manually if not enabled), this could work in the same way. Am I missing something?
Are you trying to support multiple API versions?
k
this is a very different use case. the routes are not known when the server is started
i can change that, but it impacts the APIs that I am writing
j
Wooow, ok. Then I guess you need to step out of the regular way a route matching pipeline. How and when would you know which routes will be available?
k
I have an API to add them
I am using embedded CIO server to support unit testing/mocking HTTP calls
j
Why are you referring to testing now? is this relevant?
k
i am just informing you of my use case
in case that helps
j
Mmmm testing should not impact your code, only you need to make it clean injecting dependencies, to assure it is testable. You want to modify your API because of the use case you are providing, or because you want to test something?
k
my use case is testing. this is only used to enable testing.
j
Then you don’t need to go into that direction, I believe. I’ve written an article about route testing with Ktor that could help you. Have a look: https://medium.com/@math21/testing-a-ktor-server-part-i-route-testing-84f8e82454d7 This is based in an architecture proposal I’ve done, but it may fit what you are doing.
Let me know if that helps
k
unfortunately no, i don't want to test a Ktor server
j
mmm then I don’t follow you. Your use case is testing? what does that mean?
k
the server I am starting is used to mock HTTP responses for unit testing my application
j
oh, now I understand. Why don’t you go with something like this in your Android app? https://github.com/square/okhttp/tree/master/mockwebserver
k
6 of one, half dozen of the other. I started with Ktor since I was already using it for other things.
there's also Wiremock
j
In testing, you want to avoid as much toxicity as possible, so I would avoid all the communications with any server to test your app. If you also want to check your API, there are other tools (like RestAssured in case of REST API) that could deal with API testing.
k
that's what I am doing, avoiding network requests by embedding a server
j
MockWebserver does exactly what you describe. We are using it professionally in our projects and it works fine.
k
I don't doubt that
to close the loop on this, adding routes after the server is started does function as expected
👏 1