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

  • Home
  • SEARCH
  • 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 8386831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:03:03+00:00 2026-06-09T18:03:03+00:00

A part of my application will be available as an API , so some

  • 0

A part of my application will be available as an API, so some of my pages needs to be available in JSON or XML (based on the Accept header ‘Content Type’).

I’ve used the FOSRestBundle and it works very well, but now ALL my pages are available in XML (or JSON) when sending Accept header ‘Content Type: application/xml’.

So, I would like to enable/disable this functionality for some of my controllers/actions. I would be ideal to do this using annotations.

Is that possible?

My config.yml:

fos_rest:
    view:
        formats:
            rss: false
            xml: true 
            json: true
        templating_formats:
            html: true
        force_redirects:
            html: false
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
        view_response_listener: force
    body_listener:
        decoders:
            json: acme.decoder.json
            xml: fos_rest.decoder.xml
    format_listener:
        default_priorities: ['html', 'xml', 'json', '*/*']
        fallback_format: html
        prefer_extension: false    
  • 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-09T18:03:05+00:00Added an answer on June 9, 2026 at 6:03 pm

    According to the RestBundle’s documentation, you won’t get an XML output if you don’t use a View in your controller. So, if you don’t use the @View annotation, or a View::create() in your action, and you return a classic response, you will get a HTML output.

    If you want to force the format for some reasons, you can turn the prefer_extension to true and adjust the routing definition:

    my_route:
        pattern:  /my-route
        defaults: { _controller: AcmeDemoBundle:action, _format: <format> }
    

    Where <format> is the format you want to force.

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

Sidebar

Related Questions

The third part export application we use will not properly render paragraph tags (does
I have a Flex 3.5 application that will serve multiple purposes, and as part
I'm creating a Go Google App Engine application that will be making HTTP JSON
I'm working on a Symfony2 application with an API available for other applications. I
Part of a real estate application I'm writing will allow a user to subscribe
This is a two part question. Our iPhone application has a screen which needs
Part of my application depends on JavaMail, moving arranging messages etc. Is it possible
Part of an application I'm writing allows for users to upload images which I
A part of the application that I am working on is a legacy Vb6
A part of the application I'm working on is an swf that shows a

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.