Closed kraih closed 3 years ago
My $.02 would simply be that I have always greatly enjoyed being able to smack .json
, .html
, .txt
or whatever on the url and have the application respond based on that. The response being a template rendered without hitting a controller or simply a controller method calling $c->respond_to(...)
with the types supported. Usually the calls to respond_to()
supplies an any => {...}
to catch whenever an unsupported format is requested. And if not, well, then the logs will say so and we can respond to that appropriately.
I'll try to think a bit more about the above suggestions and see if I have something useful to propose. Though I do assume you've covered the options here pretty well.
There are other "more creative" options too that i have not yet mentioned. Such as another special format variant that captures arbitrary extensions ($r->get('/foo' => [format => '*'])
), but then does not merge them into the stash (avoiding the 9.11 problem). And then have $c->respond_to(...)
still look into the place where this new variant stored the extension (say $c->stash->{'mojo.format'} = 'json'
).
Another possible solution would be to make all format settings inheritable by nested routes. It's actually completely backwards compatible, i already have a branch with a patch. https://github.com/mojolicious/mojo/compare/format_inheritance
The patch has been merged, so we now have format inheritance. That makes formats in the route pattern a lot less necessary. In fact, if used in the pattern of the parent route it might even end up looking a bit awkward.
And released with 9.16. I think that might be a good enough solution for this issue. We'll have to revisit the issue depending on how the user feedback turns out.
After the unfortunate 9.11 release, which had to disable format detection, using formats has become rather verbose.
There are many things we could do to improve that. For example we could allow format alternatives in the route pattern.
Or we could use a named placeholder that allows for types to be reused.
There could also be variants that make the format optional from the pattern without requiring
format => undef
.What do you think? How would you like to declare formats for a route?