<@UJV6CBCKW> you can obviously do either, but pers...
# http4k
d
@Razi Kheir you can obviously do either, but personally I prefer the path based routing, especially when using the contracts module with OpenApi as it makes it very clear in the docs that both exist and the different request/response types that can be present for each - also this multi-message type is actually something that the swagger UI does not currently support (or at least last time I checked). The approach also makes the overall route handler code easier to read and to test - less logic == simpler. 🙃 . And when it comes time to remove the old routes you can just delete the entire old code instead of having to unpick the switching logic for the latest version from the old.
r
So your saying not to pass a version, just make a whole new route, and move any shared code into maybe an injected handler? Or actually share most of the code too? 😮 I know this is not http4k specific, just wondering what the pros do haha
d
Yep - whole new route, grouped under a specific version namespace. How DRY you keep your code is an age-old debate 😆 - presumably if the code is due to be removed (fairly) soon then extracting out the common logic may be premature (as long as the coverage is still there). "The pros" as you refer to also cannot decide! If you find that there is a lot of code in your handlers then that may be a signal that there is another function waiting to be extracted anyway, so that the handler responsibility is just to unpack the request, pass it on, then deal with the response (all of which will organise vary between v1 and V2. And in Kotlin there is nothing to stop you putting v1 and V2 code in the same file
🎉 1
r
Thanks 🙂
I will make a new route for the v2 of that endpoint. I guess i’ll just have two separate functions for the specific differences of v1/v2 inside of the route’s handler class. I don’t like to have too many static functions around, it makes testing more difficult sometimes.
As always thanks for the advice 🙂
d
np 🙂
you can do something like this which will allow you to keep everything encapsulated as well:
Copy code
class MyEndpoint(private val someDependency: ...) {
    
    fun v1(): HttpHandler ...
    fun v2(): HttpHandler ...
}
👍 1