Is anyone used put, get, post, delete annotations(https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Controller/Annotations/) in controller.
I’m trying to use it like this, but it still takes get methods. What is the purpose of those Annotations in FOSRestBundle
/**
* @Route("/get/{id}", defaults={"_format" = "json"})
* @Post
*/
public function getObject($id) {
$object = $this->getService()->findById($id);
return $object;
}
I want to share info about all annotations.
@Get, @Post, @Put, @Delete, @Head, @Patch are shortcuts for @Route + @Method, instead of using them both, you can just specify one, e.g.:
Info about @View is in doc: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.md
Name prefix can be added either to routing.yml file or as a annotation. It is also documented – https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/6-automatic-route-generation_multiple-restful-controllers.md :
@Prefix is especially useful when you have parent resource and need to add prefix before child one.
Example:
parent:
child:
Now the action getCommentAction corresponds with /users/{slug}/comments/{id} path.
With @Prefix(“some_prefix”) generated path will be /users/{slug}/some_prefix/comments/{id}
And by using the @NoRoute method-level annotation, route won’t be generated.