Request format no longer in params?

There is a fine answer

on SO by @chrismccord about pleasant pattern-matching request format on controller actions, followed by a few comments saying that it does not work. Well - I checked - it doesn’t. A suggestion of digging into private fields of conn instead unfortunately seems far less elegant. I assume this particular answer’s author knew what he was talking about :wink: In such case the param must have been removed at some point. And yes, I can imagine valid reasons for this removal but would like to know a) what was the actual rationale, and b) if there’s any replacement for this, other than mentioned in the comments to the answer (conn/private/phoenix_format) that could be used to pattern-match on controller actions?

1 Like

You can use Phoenix.Controller.get_format/1 to get the format for the current request.

Also note that the param key is "_format" :slight_smile:

1 Like

There‘s also the option to change the parameters on controller actions:

https://kobrakai.de/kolumne/alternative-parameters-for-phoenix-controller-actions/

4 Likes

Yes, and then I surely can case the output inside function body. But how do you propose I pattern-match controller action functions using this?

Right. In such case I could “massage” whatever’s passed down to actions as I see fit and problem solved. OTOH it feels a bit like wrestling with the framework rather than working with it :wink: – you know what I mean? It’s probably the most flexible way though.

That’s for sure a valid concern, but this is a documented feature of the framework – just a rarely used one.