phly / PhlyRestfully

ZF2 module for creating RESTful JSON APIs using HAL and API-Problem
108 stars 45 forks source link

Doing a request without accept header causes an exception #88

Open macnibblet opened 11 years ago

macnibblet commented 11 years ago

I had this strange error with my application just now until i figured out that i was not setting the Accept header.

Exposed message was Zend\View\Renderer\PhpRenderer::render: Unable to render template "phly-restfully/resource/get"; resolver could not resolve to a file

weierophinney commented 11 years ago

Basically, we have the ability to set Accept criteria via the "accept_criteria" configuration key of each controller. However, this always defaults to the default ViewModel implementation -- which means the default renderer implementation, the PhpRenderer, will be selected.

So, you have a couple of options currently:

The question I have is: should this be a feature of the module? In other words should I have a listener by default, and allow opting-in to it by selected resource controller?

weierophinney commented 11 years ago

@macnibblet Any comments on the above?

macnibblet commented 11 years ago

I like the second idea of using a listener and short circuiting with an ApiProblem with appropriate information and a http status code of 406.

Is there any good use case for using a post-check ?

macnibblet commented 11 years ago

Another interesting issue i found is that angularjs default Content-Type header is application/xml which caused some really weird and unexpected behavior and also should be resolved.