Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:30:23+00:00 2026-06-01T06:30:23+00:00

Is anyone used put, get, post, delete annotations(https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Controller/Annotations/) in controller. I’m trying to use

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:30:24+00:00Added an answer on June 1, 2026 at 6:30 am

    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.:

        /**
         * @Get("/hello/{id}")
         * 
         */
        public function helloAction($id)
        {
            return array();
        }
    

    Info about @View is in doc: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.md

    @View //Guess template name
    @View("AcmeHelloBundle::layout.html.twig") //Load Resources/views/layout.html.twig
    @View("AcmeHelloBundle::layout.html.twig", templateVar="test") // if returned data doesn't 
        // have a key (e.g. return array("string", 5) instead of default variable 'data', 
        // it's placed inside 'test' variable inside template.
    @View(statusCode=204) // set HTTP header's status code
    

    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 :

    Sometimes, routes auto-naming will lead to route names collisions, so
    RestBundle route collections provides a name_prefix (name-prefix for
    xml/yml and @NamePrefix for annotations) parameter:

      #src/Acme/HelloBundle/Resources/config/users_routes.yml comments:
         type:         rest
         resource:     "@AcmeHelloBundle\Controller\CommentsController"
         name_prefix:  api_
    

    With this configuration, route name would become:
    api_vote_user_comment

    @Prefix is especially useful when you have parent resource and need to add prefix before child one.
    Example:

    parent:

    class UsersController extends Controller
    {
        public function getUserAction($slug)
        {} // "get_user"   [GET] /users/{slug}
    }
    

    child:

    class CommentsController extends Controller
    {
        public function getCommentAction($slug, $id)
        {} // "get_user_comment"    [GET] 
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone used jquery to take data from one form field and put it
Has anyone used javascript/ajax to take data from one form field and put it
Has anyone used the lockfile utility that ships with procmail in conjunction with NFS
Has anyone used Lucene.NET rather than using the full text search that comes with
Has anyone used Mono, the open source .NET implementation on a large or medium
Has anyone used Rhino igloo in a non-trivial project? I am curious if it's
Has anyone used C# with a Sales Logix database?
Has anyone used Ruby/Rails with a Sales Logix database?
Has anyone used CSLA in an application that has a WPF front end and
Has anyone used Pear: Spreadsheet_Excel_Writer ? The Formatting Tutorial lists a script similar to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.