-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Force JSON output regardless of URL extension #1067
Comments
This is kind of the pattern we follow though. I think it would be somewhat confusing and inconsistent if suddenly you could return different output formats from different extensions. Have you considered forcing a redirect for your html route to the |
I'm ok with adding support for this @w00fz but it will probably not be something in admin. It's a very advanced feature that is not going to be used often. |
I'm thinking from a web service perspective. URLs are supposed to be opaque. One URL represents one resource, which can have multiple representations. The client is supposed to be able to send an So with the Webmention plugin, when you submit a mention, you can optionally be given a URL to check later for the status of your request. If the client is a person, they may want an HTML response. They'd just check it from their browser (automatically a As it stands, I am not aware of a method for me to, from a plugin, force a response in a specific MIME type. I can change it's template, but I can't force Grav to use the And yes, URL opaqueness aside, you should certainly refrain from returning JSON output if the URL ends with And while it would be great if Grav just did this automatically (maybe a |
Ok I can see some valid points here and I can see a couple things we could improve this, imo. I think that, and I am not too sure about this as I need to double check the code, we implicitly assume a direct hit to a route is HTML and that it looks for the Probably this should be smarter behind the scenes and Grav should be able to automatically determine that if a The second aspect that we could improve is what you suggest in regards of headers. I can see now your point and I agree that requesting with Is this what you had in mind also @rhukster ? Also how does this sound to you @Perlkonig ? |
If you're looking at an ideal long-term solution, then I recommend the following (I haven't dug through the source code yet).
This would remove all responsibility from the content creators. They'd just need to make sure the templates are there or are conspicuously absent. The rest is up to the agent. A page-level override also seems cheap to implement and would be useful both as a stop gap and also as an override once the high-level changes are made. I recognize this is a pretty major change, but I think it would be a very positive one. |
My idea was to at least add the page-level override. But that |
Ok, added this and implemented Sitemap using this functionality: getgrav/grav-plugin-sitemap@00c2373 Page-level override only at this point. |
You 'da man. |
Proof of concept in PR #1088 |
I have a plugin that returns a status reports. It should always be JSON (using the
*.json.twig
template). I don't want to force the client to append.json
to the URL. I just want to programmatically trigger the response as JSON. It's currently not possible to do this.The text was updated successfully, but these errors were encountered: