laminas-api-tools / api-tools-rest

Laminas Module providing structure for RESTful resources
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
7 stars 16 forks source link

Can't use my own model with content negotiation #5

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

Hi!

I got an API with content negotiation. For binaries resources, the caller don't know the mime type. Typically, if it's a element in an HTML page, I can't specify headers.

When the resource GET method is called, the server knows its type, and I can return an ImageModel or PdfModel or whatever I need instead of HalEntity or HalCollection, but the RestController encapsulate my model into a new entity and a ContentNegotiationViewModel... :-/

Rest controller should bypass contentNegotiation if I want to use my own model.


Originally posted by @webaaz at https://github.com/zfcampus/zf-rest/issues/89

weierophinney commented 4 years ago

I use a patch to bypass, setting headers in the resource

$this->getEvent()->getRequest()->getHeaders()->addHeaderLine('content-type', 'application/pdf');

I think it's not the best way...


Originally posted by @webaaz at https://github.com/zfcampus/zf-rest/issues/89#issuecomment-135001417