Repository navigation
Updating to Hamlet 3.2 - #4152
Conversation
|
|
||
| public function getResponse(Request $request): Response | ||
| { | ||
| if ($this->json) { |
There was a problem hiding this comment.
Out of curiosity, might you see better results if you create two different resources that implement WebResource, like PlaintextResource and JsonResource? Having to hit this conditional on every request seems like an unnecessary expense.
There was a problem hiding this comment.
Generally speaking the resources in Hamlet should be organised not around formats, but around data they send back.
Resource -> checks method types, negotiates content type, produces data, defines appropriate response code, wraps data into appropriate entity
Entity -> knows how to format data and send appropriate entity-specific headers.
Response -> pretty much a collection of status code + headers + entity.
There was a problem hiding this comment.
I see what you're saying. Just pointing out that this HelloResource class could be broken up into two different classes instead of instantiating the same class with a json boolean and performing that extra conditional on every request. For benchmarking purposes, hundreds of thousands of requests checking on that boolean is some non-zero expense. I was thinking:
class PlaintextResource implements WebResource
{
public function getResponse(Request $request): Response
{
$entity = new PlainTextEntity('Hello, World!');
return new SimpleOKResponse($entity);
}
}
And another for the json route. In the same way you have the db, update, and fortunes resources. Just a thought to save some ticks.
* Updating to Hamlet 3.1 * Updating to Hamlet 3.2 * uncomment a line
No description provided.