Currently I came to a scenario where I need to dynamically compose or set new route while web-server continues to run without restarting it. As I understand it is not currently supported. I think this can be a very useful feature.
Routes are just functions RequestContext => Future[RouteResult], so you can implement all the dynamic behavior you'd like to have. In the simplest case you could read a (volatile) var for every request with the current route and execute that.
E.g.
private[this] @volatile var _currentRoute: Route = initialRoute
val rootRoute: Route = ctx => _currentRoute(ctx)
// pass rootRoute to bindAndHandle
// or:
// val rootRoute = pass { _currentRoute }
// where `pass` is a predefined directive that just executes the given route
This could probably be packaged nicer to hide the mutable state. Would that work for you?
Hmmm... yeah this should work, I will try it! Thanks, a lot!
Most helpful comment
Routes are just functions
RequestContext => Future[RouteResult], so you can implement all the dynamic behavior you'd like to have. In the simplest case you could read a (volatile)varfor every request with the current route and execute that.E.g.
This could probably be packaged nicer to hide the mutable state. Would that work for you?