An open API service indexing awesome lists of open source software.

https://github.com/notrab/dumbo

A lightweight, friendly PHP framework for HTTP.
https://github.com/notrab/dumbo

dumbo micro-framework php

Last synced: 9 months ago
JSON representation

A lightweight, friendly PHP framework for HTTP.

Awesome Lists containing this project

README

          


Dumbo

Dumbo


A lightweight, friendly PHP framework for HTTP — Inspired by Hono.




Discord



Contributors



Total downloads



Examples

## Features

- 🚀 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

## Install

```bash
composer require notrab/dumbo
```

## Quickstart

Here's a basic example of how it works!

```php
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](/examples) directory for more quickstarts.

## License

Dumbo is open-sourced software licensed under the [MIT license](LICENSE).

## Contributors

![Contributors](https://contrib.nn.ci/api?repo=notrab/dumbo)

## Documentation

### Routing

```php
get('/users', function($context) { /* ... */ });
$app->post('/users', function($context) { /* ... */ });
$app->put('/users/:id', function($context) { /* ... */ });
$app->delete('/users/:id', function($context) { /* ... */ });
```

#### Params

```php
get('/users/:id', function($context) {
$id = $context->req->param('id');

return $context->json(['id' => $id]);
});
```

#### Nested

```php
get('/nested', function($context) {
return $context->text('This is a nested route');
});

$app->route('/prefix', $nestedApp);

```

### Context

```php
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');
});
```

### Response

```php
json(['key' => 'value']);
return $context->text('Hello, World!');
return $context->html('

Hello, World!

');
return $context->redirect('/new-url');
```

### Middleware

```php
use(function($context, $next) {
$response = $next($context);

return $response;
});
```

### Custom context

```php
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();
```