wiro
wiro copied to clipboard
Add annotation for applying custom functions to routes
requirements
- Wiro user should be allowed to modify all the routes of a given server applying a custom function on the whole router.
- Wiro user should be allowed to selectively modify wiro routes applying custom functions.
specs
Requirement 1
The function should be passed to HttpRPCServer
. Passing the function to deriveRouter
would be messy (see discussion).
Requirement 2
class Cat {
val f: Route => Route
@command
@apply(f)
def meow ...
}
Implementation should be pretty straightforward using MethodMetaData
.
Note: Route => Route
signature is possibly correct, though I'm not sure about it. Consider changing the signature to match the requirement. Even the annotation name apply
might be misleading in scala, feel free to propose something different.
misc
{optional: other useful info}
why putting the f
function inside the Class?
I would like to define this at the router level, e.g. in the deriveRouter
method, or - even better - at the Server level.
Applying f
on the specific method has finer granularity. The use case I had in mind was to selectively applying this to a few routes.
We can actually have both the annotation on the method and an additional argument in deriveRoute
.
Implementation-wise adding an optional argument to deriveRoute
macro is a little trickier than adding an annotation. We are currently handling optional arguments in macros using method overloading... we would end up with something like:
def deriveRouter[A](a: A): Router
def deriveRouter[A](a: A, printer: Printer): Router
def deriveRouter[A](a: A, printer: Printer, f: Route => Route): Router
def deriveRouter[A](a: A, f: Route => Route): Router
If we want to add other arguments to deriveRouter
I think we need to find a smarter way.
My concern is that if I want to transform any request across my router definition, I now have to do it in N places.
We definitely need a way to do this for the whole Server.
We can do that on HttpRPCServer
... should be pretty easy.
I updated the requirements...
Do requirement 2 (@apply(f) def meow = ???
) make sense at all?