Quickstart
Hello world
-
Create a project and require Dumbo with Composer:
mkdir my-app && cd my-app composer require notrab/dumbo -
Create an
index.phpfile:<?php require __DIR__ . '/vendor/autoload.php'; use Dumbo\Dumbo; $app = new Dumbo(); $app->get('/', function ($context) { return $context->text('Hello Dumbo!'); }); $app->run(); -
Start PHP's built-in server, using
index.phpas the router:php -S localhost:8000 index.php -
Open http://localhost:8000 and say hello. π
A bigger example
<?php
require __DIR__ . '/vendor/autoload.php';
use Dumbo\Dumbo;
$app = new Dumbo();
$app->use(function ($context, $next) {
$context->set('message', 'Hello from middleware!');
return $next($context);
});
$app->get('/', function ($context) {
return $context->json([
'message' => $context->get('message'),
'timestamp' => time(),
]);
});
$app->get('/users/:id', function ($context) {
$id = $context->req->param('id');
return $context->json(['userId' => $id]);
});
$app->post('/users', function ($context) {
$body = $context->req->body();
return $context->json($body, 201);
});
$app->run();