Reputation: 695
I have 5 controllers in akka-http. Each endpoint has 5 endpoints(routes). Now I need to introduce versioning for those. All endpoints should be prefixed with /version1
.
For example if there was an endpoint xyz
now it should be /version1/xyz
.
One of the ways is to add a pathPrefix
But it needs to be added to each controller.
Is there way to add it at a common place so that it appears for all endpoints.
I am using akka-http with scala.
Upvotes: 1
Views: 363
Reputation: 17933
Indirect Answer
Aleksey Isachenkov's answer is the correct direct solution.
One alternative is to put versioning in the hostname
instead of the path. Once you have "version1" of your Route
values in source-control then you can tag that checkin as "version1", deploy it into production, and then use DNS entries to set the service name to version1.myservice.com
.
Then, once newer functionality becomes necessary you update your code and tag it in source-control as "version2". Release this updated build and use DNS to set the name as version2.myservice.com
, while still keeping the version1 instance running. This would result in two active services running independently.
The benefits of this method are:
production.myservice.com
point to whichever version of the service you want. For example: once you've released version24.myservice.com
and tested it for a while you can update the production.myservice.com
pointer to go to 24 from 23. The old version can stay running for any users that don't want to upgrade, but anybody who wants the latest version can always use "production".Upvotes: 0
Reputation: 1240
You can create a base route, that accepts paths like /version1/...
and refers to internal routes without path prefix.
val version1Route = path("xyz") {
...
}
val version2Route = path("xyz") {
...
}
val route = pathPrefix("version1") {
version1Route
} ~ pathPrefix("version2") {
version2Route
}
Upvotes: 3