Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factory methods for common HTML/JSON/plaintext/XML response types #439

Merged
merged 2 commits into from
Feb 3, 2022

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