-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathserver.php
More file actions
37 lines (29 loc) · 879 Bytes
/
server.php
File metadata and controls
37 lines (29 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\Http\Adapter\Swoole\Server;
use Utopia\Validator\Text;
class User
{
public function __construct(public $name)
{
}
}
$container = new Container();
$container->set('user', fn () => new User("Demo user"));
Http::get('/')
->param('name', 'World', new Text(256), 'Name to greet. Optional, max length 256.', true)
->inject('response')
->action(function (string $name, Response $response) {
$response->send('Hello ' . $name);
});
Http::get('/user')
->inject('response')
->inject('user')
->action(function (Response $response, User $user) {
$response->send('Hello ' . $user->name);
});
$http = new Http(new Server('0.0.0.0', '80'), $container, 'America/New_York');
$http->start();