Skip to content

Commit 29188ed

Browse files
author
designcise
committed
feat: added example for json response
1 parent c324e42 commit 29188ed

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

www/server/app/Controller/DefaultController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Psr\Http\Server\RequestHandlerInterface;
99
use BitFrame\Container;
1010
use BitFrame\FastRoute\Route;
11+
use BitFrame\Http\Message\JsonResponse;
1112

1213
class DefaultController
1314
{
@@ -16,7 +17,7 @@ public function __construct(
1617
) {}
1718

1819
#[Route(['GET'], '/hello/{action}')]
19-
public function testAction(
20+
public function indexAction(
2021
ServerRequestInterface $request,
2122
RequestHandlerInterface $handler,
2223
): ResponseInterface {
@@ -29,4 +30,17 @@ public function testAction(
2930

3031
return $response;
3132
}
33+
34+
#[Route(['GET'], '/json')]
35+
public function jsonAction(): ResponseInterface
36+
{
37+
$globals = $this->container['globals'];
38+
39+
return JsonResponse::create([
40+
'data' => [
41+
'title' => $globals['title'],
42+
'mainHeading' => 'Build Something Amazing Today!',
43+
],
44+
]);
45+
}
3246
}

0 commit comments

Comments
 (0)