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
[WIP] Accept header - Version support #612
Conversation
This is a first PR about my idea. It will add support for allow or not the access to methods by checking version passed into the Accept HTTP header
@lsmith77 Do you see more what i'm doing ? |
Thank you for the PR. I am at a conference this weekend but should definitely have time on the train home tomorrow. |
related to #607 |
'event' => 'kernel.controller', | ||
'method' => 'onKernelController', | ||
'priority' => -255 | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in the DI extension, not in a compiler pass
Hi @stof, Could you review ? |
'event' => 'kernel.controller', | ||
'method' => 'onKernelController', | ||
'priority' => -255 | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be defined in the XML file like other services, not in the PHP file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do this in PHP as i'm not sure how to make the condition for serialization context argument. Can you say me more ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<argument type="service" id="fos_rest.version.serialisation_context" on-invalid="null" />
Just to make sure, with this implementation declaring 2 controllers with the same path but with different versions won't work in practice right ? |
The idea I want to adress is, I want to expose methods only for version. I want to have the same application serve multiple version of the API. And, yes, if you declare 2 controller with an action with the same route, it do not work. But we don't need to have a same method in two controllers . |
Sometimes there is just too much difference between two versions that having both in one controller would be impractical. |
Yes, but in this case, the method you use the Until annotation, and you declare another method with a Since annotation. If you don't want to change the name of the method, you have to switch on the version inside the main method and route into Vx or Vy method |
right .. this is why ideally the entire version handling would be handled inside the routing or at least be associated with the routing configuration. see also #561 |
Yes, it could be better to handle the version inside the routing. Any idea on how to implement it ? |
@lsmith77 Can you explain me more ? IRC ? |
@amenophis sure catch me tomorrow in #symfony-dev on freenode. today i am too tired from practice. |
@lsmith77 OK ! thanks |
so FOSRestBundle master now can set the matched media type as a request attribute #621 |
Can i do something ? |
public function onKernelRequest(GetResponseEvent $event) { | ||
$request = $event->getRequest(); | ||
|
||
$acceptHeader = $request->headers->get('Accept'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should now be $request->attributes->get('media_type');
however it requires FOSRestBundle master with the format listener enabled.
@lsmith77 I'm not sure about my rebase ... is it OK ? |
return $this->version; | ||
} | ||
|
||
public function __construct(Reader $reader, $regex, Context $context = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
needs to be on a newline
@lsmith77 Done. |
like discussed via IRC:
|
@@ -11,6 +11,7 @@ | |||
|
|||
namespace FOS\RestBundle\Controller; | |||
|
|||
use JMS\Serializer\SerializationContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed
can you squash your commits? http://symfony.com/doc/current/contributing/code/patches.html#rework-your-patch |
The JMS Serializer has annotations for |
Because FOSRestBundle supports the Symfony serializer as well. |
I see, thx for the hint :) |
return; | ||
} | ||
|
||
foreach ($annotations as $annotation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing I am wondering here is how to make it possible that one could annotate multiple controllers that each cover a different version of the API for the same path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this goes into the direction of what I wanted to achieve in https://github.com/FriendsOfSymfony/FOSRestBundle/pull/561/files#diff-3b898a9b28925d8dc60210cb06ed7719R14
@amenophis I have extracted the version detection part of your PR into a new PR -> #636 This way we can add the feature quickly. For the annotations I then want to come up with a fancier solution which would work as explained in #637 |
This is a first PR about my idea. It will add support for allow or not the access to methods by checking version passed into the Accept HTTP header