Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback handling of ordinary ....Response objects #26

Closed
lenar opened this issue Apr 26, 2011 · 7 comments
Closed

fallback handling of ordinary ....Response objects #26

lenar opened this issue Apr 26, 2011 · 7 comments

Comments

@lenar
Copy link
Contributor

lenar commented Apr 26, 2011

There should be some way to specify that I want all Response objects
returned by actions modified (normalized/serialized) to requested format.

Currently, if action returns Response object (and json format is requested by Accept: header)
the content is thrown at browser as-is, but Content-Type is modifed to reflect requested format.
I mean: content returned to client is html but content-type says it's application/json for example.

I could implement my own onCoreResponse listener to achieve that for my own needs,
but shouldn't this kind of fallback functionality be included in RestBundle?

It's would be mainly useful in cases where I cannot use RestBundle\View (3rd party bundles).
For example FOSUserBundle - it hardcodes responses (and templates used) and this would
give the opportunity to at least convert those responses to format that is meaningfully handleable
by browser app.

Any comments or extra ideas? I don't feel my thoughts regarding this are mature enough at this point.

@lsmith77
Copy link
Member

Fixing other Bundle is beyond the scope of this Bundle. If you want to JSON-fy 3rd party Bundles I recommend looking at https://github.com/liip/MultiplexBundle

@lenar
Copy link
Contributor Author

lenar commented Apr 26, 2011

Really, I don't need multiplexing support. I want transparent output-format-agnostic support.
This bundle almost provides it (there is excellent support for exceptions) but falls short
converting normal (The Book) responses. I only think it would be nice if this bundle included
a way to specify serializer for this kind of cases. The bundle really has all the other components
needed. Why should I look at MultiplexBundle in this case? It's not logical.

Sorry if it's too much to be asked.

@lsmith77
Copy link
Member

Maybe I didnt understand your request, but if you want to JSON-ify UserBundle actions, the MultiplexBundle does what you need, since it allows you to define what format you want returned. If you need something else could you maybe come up with a php example?

@lenar
Copy link
Contributor Author

lenar commented Apr 27, 2011

I didn't argue that MultiplexBundle wouldn'y give me what I need. Yes, it does. But it feels kind of hacky and certainly not as flexible as it can be. Maybe that's just me. But.

But this bundle would give me the support of different serializers and normalizers which would be very nice even
in the case of the common "return new Response(...)" and "return new RedirectResponse()" from the actions.
I would even argue that MultiplexBundle does too much - it should just multiplex. And the format conversion
should be done by some other bundle. Currently the RestBundle has the best implementation of this conversion.
So MultiplexBundle should IMHO actually live on and together with RestBundle.

And of course since exceptions can be already nicely and automatically converted to suitable format with this bundle I
only thought that handling (of course configurable as exceptions are) ordinary ...Responses in the same way would
only be consistent and logical. I really expected that this bundle does this when I found it - because it felt
right and because it's README.md had this sentence:

For now the Bundle provides a view layer to enable output format agnostic Controllers, which includes the ability to handle redirects differently based on a service container aware Serializer service that can lazy load encoders and normalizers.

This sentence really got me excited and I never thought it only provides this ability when using special View class. I really can see the format conversion for ordinary Responses can be done very efficiently in this bundle
(and so much more than MultiplexBundle) and so it makes sense for me.

Maybe I'm wrong. Maybe I'm missing something. I don't know.

@lsmith77
Copy link
Member

I still dont get what the RestBundle is supposed to do here.

@lsmith77 lsmith77 reopened this Apr 27, 2011
@lenar
Copy link
Contributor Author

lenar commented Apr 27, 2011

Provide a way to match the behavior of ordinary exceptions

framework:
    exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'

for ordinary Responses.

Ok, I can provide some example code which maybe could be included in RestBundle but it takes a bit time.
Until then, let this conversation rest.

@lsmith77
Copy link
Member

I still dont think this should be part of RestBundle, but I guess you can create a Response listener that does something. Still I dont know what the Response listener is supposed to do with the content of the 3rd party bundle. But if you got something you can send a PR and we can discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants