2024-11-18 02:37:00
github.com
A lightweight, friendly PHP framework for HTTP — Inspired by Hono.
- 🚀 Lightweight and fast
- 🧩 Middleware support
- 🛣️ Flexible routing with parameters
- 🔒 Built-in security features (CSRF, JWT)
- 🍪 Cookie management
- 📅 Date helpers
- 🔍 Request ID for tracing
- 📁 Static file serving
- 🔐 Basic and Bearer authentication
- 📝 Logging support
- 🗃️ HTTP caching
- 🔄 CORS support
- 🧬 Environment-based configuration
composer require notrab/dumbo
Here’s a basic example of how it works!
‘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();”>
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();
See the examples directory for more quickstarts.
Dumbo is open-sourced software licensed under the MIT license.
$app->get('/users', function($context) { /* ... */ });
$app->post('/users', function($context) { /* ... */ });
$app->put('/users/:id', function($context) { /* ... */ });
$app->delete('/users/:id', function($context) { /* ... */ });
$app->get('/users/:id', function($context) {
$id = $context->req->param('id');
return $context->json(['id' => $id]);
});
$nestedApp = new Dumbo();
$nestedApp->get('/nested', function($context) {
return $context->text('This is a nested route');
});
$app->route('/prefix', $nestedApp);
$routePath = $context->req->routePath();
$queryParam = $context->req->query(‘param’);
$tags = $context->req->queries(‘tags’);
$body = $context->req->body();
$userAgent = $context->req->header(‘User-Agent’);
});”>
$app->get('/', function($context) {
$pathname = $context->req->pathname();
$routePath = $context->req->routePath();
$queryParam = $context->req->query('param');
$tags = $context->req->queries('tags');
$body = $context->req->body();
$userAgent = $context->req->header('User-Agent');
});
return $context->json(['key' => 'value']);
return $context->text('Hello, World!');
return $context->html('');
return $context->redirect('/new-url');
$app->use(function($context, $next) {
$response = $next($context);
return $response;
});
$app = new Dumbo();
// Set configuration values
$app->set('DB_URL', 'mysql://user:pass@localhost/mydb');
$app->set('API_KEY', 'your-secret-key');
$app->set('DEBUG', true);
// Get configuration values
$dbUrl = $app->get('DB_URL');
$apiKey = $app->get('API_KEY');
$debug = $app->get('DEBUG');
// Use configuration in your routes
$app->get('/api/data', function(Context $context) {
$apiKey = $context->get('API_KEY');
// Use $apiKey in your logic...
return $context->json(['message' => 'API key is set']);
});
$app->run();
Support Techcratic
If you find value in Techcratic’s insights and articles, consider supporting us with Bitcoin. Your support helps me, as a solo operator, continue delivering high-quality content while managing all the technical aspects, from server maintenance to blog writing, future updates, and improvements. Support Innovation! Thank you.
Bitcoin Address:
bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge
Please verify this address before sending funds.
Bitcoin QR Code
Simply scan the QR code below to support Techcratic.
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.