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

Update to use HTTP status code constants and JSON/HTML response helpers #24

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,13 @@ <h2 class="text-base font-semibold tracking-wider text-indigo-600 uppercase">Too
$app = new FrameworkX\App();

$app->get('/', function () {
return new React\Http\Message\Response(
200,
[],
return React\Http\Message\Response::plaintext(
"Hello wörld!\n"
);
});

$app->get('/users/{name}', function (Psr\Http\Message\ServerRequestInterface $request) {
return new React\Http\Message\Response(
200,
[],
return React\Http\Message\Response::plaintext(
"Hello " . $request->getAttribute('name') . "!\n"
);
});
Expand Down Expand Up @@ -318,13 +314,8 @@ <h3 class="text-2xl font-extrabold text-gray-900 tracking-tight sm:text-3xl">

<pre class="text-left mt-12 col-span-full shadow-2xl"><code class="php rounded-md">$app->get('/users', function () {
$users = [['name' => 'Alice'], ['name' => 'Bob']];
$json = json_encode($users);

return new React\Http\Message\Response(
200,
[
'Content-Type' => 'application/json'
],
return React\Http\Message\Response::json(
$json
);
});
Expand Down Expand Up @@ -523,9 +514,7 @@ <h3 class="text-2xl font-extrabold text-gray-900 tracking-tight sm:text-3xl">
assert($result instanceof React\MySQL\QueryResult);
$data = $result->resultRows[0]['title'];

return new React\Http\Message\Response(
200,
[],
return React\Http\Message\Response::plaintext(
$data
);
});
Expand Down Expand Up @@ -621,7 +610,7 @@ <h3 class="text-2xl font-extrabold text-gray-900 tracking-tight sm:text-3xl">
});

return new React\Http\Message\Response(
200,
React\Http\Message\Response::STATUS_OK,
[
'Content-Type' => 'text/event-stream'
],
Expand Down Expand Up @@ -826,17 +815,13 @@ <h2 class="text-base font-semibold tracking-wider text-indigo-600 uppercase">Qui
$app = new FrameworkX\App();

$app->get('/', function () {
return new React\Http\Message\Response(
200,
[],
return React\Http\Message\Response::plaintext(
"Hello wörld!\n"
);
});

$app->get('/users/{name}', function (Psr\Http\Message\ServerRequestInterface $request) {
return new React\Http\Message\Response(
200,
[],
return new React\Http\Message\Response::plaintext(
"Hello " . $request->getAttribute('name') . "!\n"
);
});
Expand Down