Skip to content

Conversation

@clue
Copy link
Member

@clue clue commented Feb 3, 2022

This changeset adds factory methods for common HTML/JSON/plaintext/XML response types:

$response = React\Http\Response\html("<h1>Hello wörld!</h1>\n");
$response = React\Http\Response\json(['message' => 'Hello wörld!']);
$response = React\Http\Response\plaintext("Hello wörld!\n");
$response = React\Http\Response\xml("<message>Hello wörld!</message>\n");

Using the new factory methods is entirely optional and directly using the Response constructor remains supported of course, but we now use these factory methods throughout our documentation and examples to make them more readable. Accordingly, this does not affect backwards compatibility.

This builds on top of #403 (thank you @WyriHaximus!), but instead of exposing a new class, this changeset simply adds a number of static methods to the existing Response class. This makes it easier to use these methods in application code because no separate import is required, in particular when using the HTTP status code constants implemented in #432.

Supersedes / closes #403
Builds on top of #432
Refs clue/reactphp-ndjson#14

@clue clue added this to the v1.6.0 milestone Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants