You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
finalclassGetPhoto
{
publicfunctionaccepts()
{
return ['text/html', 'application/json'];
}
publicfunction__invoke(int$id)
{
// The response is built based off the request formatreturn$this->responder->__invoke($this->request, $this->domain->findById($id));
}
}
The script for both scenarios above:
$matched = $autoRoute->route($request->method, $request->pathInfo, $request->contentType);
$matched->format = /* 'application/json' or 'text/html' */;
// if found for separate content negotiation methods$matched->method = /* json() or html() */;
// or if found for one single method$matched->method = /* __invoke() */;
// if not found$matched->error = /* AutoRoute\Exception\NotAcceptable */;
Personally, I like the first method, as it's simpler to understand and allows more flexibility. However, from my understanding of the ADR pattern, its the responsibility of the Responder to build and return the response as either HTML, JSON, XML, etc. Maybe, the library can support both methods?
The text was updated successfully, but these errors were encountered:
What are your thoughts about adding support for content negotiation in the actions?
In the action, using content negotiation methods:
or using an
accepts
method:The script for both scenarios above:
Personally, I like the first method, as it's simpler to understand and allows more flexibility. However, from my understanding of the ADR pattern, its the responsibility of the
Responder
to build and return the response as either HTML, JSON, XML, etc. Maybe, the library can support both methods?The text was updated successfully, but these errors were encountered: