FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.8k stars 703 forks source link

Format Listener schould omit content-type header on empty content #1555

Open akomm opened 8 years ago

akomm commented 8 years ago
fos_rest:
  format_listener:
    enabled: true
    rules:
      - { path: ^/api, priorities: [ json ], fallback_format: json, prefer_extension: false }
// route to this falls under ^/api
class Controller 
{
    public function __invoke(/* ... */)
    {
        return View::create(null, /* ... */);
    }
}

When some routes under ^/api do not return any data, format listener should omit content-type: application/json, So it should do for other formats. If there are cases where it would not make any sense, maybe add it as an option, so you can tell to omit content-type if response is empty on specific format format only.

GuilhemN commented 8 years ago

Why removing the content type ? The listener can simply return null in JSON.

akomm commented 8 years ago

Why should null be returned as JSON when an operation does not return any data? And what do you do with XML? Not every operation on a resource does return data. JSON is only an example.

GuilhemN commented 8 years ago

Well maybe we could add an option but i don't think it should be the default as some people would expect this behavior.