go-json-rest icon indicating copy to clipboard operation
go-json-rest copied to clipboard

Add support for setting middlewares that are executed after parsing the path params.

Open ruseinov opened this issue 9 years ago • 2 comments

A good use-case would be applying Semver versioning to all endpoints, right now I have to apply a middlewareFunc to every handler, because path params are not present while executing middlewares for obvious resasons.

ruseinov avatar Dec 11 '15 15:12 ruseinov

I'm trying to think about the right API for that. Would a stack of middlewares passed as a parameter of the Router would do ?

ant0ine avatar Jan 18 '16 23:01 ant0ine

I think so, might also be beneficial to have some sort of IfMiddleware that would accept a slice of middlewares/single middleware + be able to check if there's a param in the request, so, for example, if there's version param - let's enable SemVer and so forth.

I guess the same IfMiddleware might do, since it already receives a request object.

I think in this case fine-grained control is crucial, since you would most of the tie want these middlewares only in case a certain param exists.

Router middlewares sound good!

ruseinov avatar Jan 19 '16 10:01 ruseinov