Otuyh
Otuyh

Reputation: 2484

FosRestBundle mixing twig and json

I have a full working project using symfony, and i need to add some rest api inside of it.

I'm using FosRestBundle, and it's already working in my localhost using the following configs:

# FOSRest Configuration
fos_rest:
    body_listener: true
    format_listener:
        rules:
            - { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: false }
    param_fetcher_listener: true
    view:
        view_response_listener: 'force'
        formats:
           json: true

When im putting this code (that is fully working in my localhost) in the prod enviroment, the rest api continue to work, but all my other controllers is just returning me a "text" instead of html. I'm seeing the code in the screen instead of my template.

Anyone knows whats causing this behavior?

class TestRestController extends FOSRestController
{
    /**
     * @Rest\Get("/test")
     * @QueryParam(name="id")
     * @QueryParam(name="name")
     */
    public function indexAction(\FOS\RestBundle\Request\ParamFetcher $paramFetcher){
         ....
    }

}

Thanks.

Upvotes: 2

Views: 574

Answers (1)

magnetik
magnetik

Reputation: 4431

For instance if all your API instances starts with /api/..., you can use this config:

fos_rest:
    format_listener:
        rules:
          - { path: ^/api, priorities: [ json, xml ], fallback_format: json, prefer_extension: true }
          - { path: '^/', priorities: ['text/html', '*/*'], fallback_format: html, prefer_extension: true }

Upvotes: 4

Related Questions