Fork me on GitHub
Vincent Cantin18:01:04

Is it possible using Reitit to route to different handlers based on the "Accept" header field in a request?

Ben Sless18:01:07

Do you want to do some complex routing based on it or just dispatch to different handlers per content type?

Vincent Cantin18:01:21

dispatch to different handlers per "Accept" type

Ben Sless18:01:10

In that case I'd create a multimethod which dispatches in it as the handler. Reitit only routes based on path afaik


you can also add :accept key to route data, create a ring-router out of the routes, ask the flattened route tree, group by :accept, and create separate subrouter out of each. Then create a ring-handler that looks for accept and forwards to the correct sub-router. E.g. one router per defined :accept.

👍 1

At least one superfast (Go) router groups by request-method for performance.


.. same can be done in a middleware, to select a handler based on accept

👍 1

if you use middleware compilation, the perf penalty is one hash-lookup. Unless you use regexs awesome

Vincent Cantin19:01:39

Thanks. I think I will choose the middleware approach in my use case.