2024-09-05 10:04:59 +01:00
|
|
|
<?php
|
|
|
|
|
2024-09-08 09:24:05 +01:00
|
|
|
require __DIR__ . "/vendor/autoload.php";
|
2024-09-05 10:04:59 +01:00
|
|
|
|
|
|
|
use Dumbo\Dumbo;
|
|
|
|
|
|
|
|
$app = new Dumbo();
|
|
|
|
|
|
|
|
// Route with a single parameter
|
|
|
|
$app->get("/hello/:name", function ($context) {
|
|
|
|
$name = $context->req->param("name");
|
|
|
|
return $context->text("Hello, $name!");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Route with multiple parameters
|
|
|
|
$app->get("/users/:id/posts/:postId", function ($context) {
|
|
|
|
$userId = $context->req->param("id");
|
|
|
|
$postId = $context->req->param("postId");
|
|
|
|
return $context->json([
|
|
|
|
"userId" => $userId,
|
|
|
|
"postId" => $postId,
|
|
|
|
"message" => "Fetching post $postId for user $userId",
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Optional parameter (using query string)
|
|
|
|
$app->get("/", function ($context) {
|
|
|
|
$name = $context->req->query("name") ?? "Guest";
|
|
|
|
return $context->text("Greetings, $name!");
|
|
|
|
});
|
|
|
|
|
|
|
|
$app->run();
|