Feature #27118
Routing: json format should use MIME application/json by default
Status: | Rejected | Start date: | 2011-05-29 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | - | % Done: | 0% |
|
Category: | MVC | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No |
Description
Actually the format specified in routing doesnt have effect in the MIME, by default it's text/html
Whitout changing the View object common formats should be mapped to its MIMEs
JSON-> application/json
History
#1 Updated by Bastian Waidelich almost 4 years ago
- Category changed from MVC - Routing to MVC
That has to be done in the Controller or View
#2 Updated by Fernando Arconada almost 4 years ago
I think that could be useful to have an option to specify it in routing. At least JSON (and XML), that is quite common, should use the correct MIME by default whitout touching the code
#3 Updated by Bastian Waidelich almost 4 years ago
Fernando Arconada wrote:
I think that could be useful to have an option to specify it in routing.
At least JSON (and XML), that is quite common, should use the correct MIME by
default whitout touching the code
I agree, that this is useful and a pretty common requirement. But it can't be solved in the routing because the controller & view decide what headers should be returned.
What I could imagine is, that the ActionController sets the response header before rendering the view.
#4 Updated by Alexander Berl over 3 years ago
Wouldn't this be a case for the RequestHandler, the same way it is currently done for rss/atom feed headers?
/** * Handles the web request. The response will automatically be sent to the client. * * @return void * @author Robert Lemke <robert@typo3.org> */ public function handleRequest() { $request = $this->requestBuilder->build(); $response = new Response(); switch ($request->getFormat()) { case 'rss.xml' : case 'rss' : $response->setHeader('Content-Type', 'application/rss+xml'); break; case 'atom.xml' : case 'atom' : $response->setHeader('Content-Type', 'application/atom+xml'); break; } $this->dispatcher->dispatch($request, $response); $response->send(); }
This way the controller&view can still override the response header, but don't have to set them for those common formats.
#5 Updated by Christian Müller over 3 years ago
- Status changed from New to Rejected
- Has patch set to No
This has been removed. The JsonView in the FLOW3 package sets the header correctly, you should do the same if you decide to use your own view.