Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Utopia HTTP is a PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. This library is maintained by the [Appwrite team](https://appwrite.io).

Utopia HTTP is dependency-free. Any extra features, such as authentication or caching are available as standalone models in order to keep the framework core clean, light, and easy to learn.
Utopia HTTP keeps routing and request lifecycle concerns separate from resource wiring by relying on the standalone Utopia DI package for dependency injection.

## Getting Started

Expand All @@ -23,11 +23,14 @@ Init your first application in `src/server.php`:
```php
require_once __DIR__.'/../vendor/autoload.php';

use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

$container = new Container();

Http::get('/hello-world') // Define Route
->inject('request')
->inject('response')
Expand All @@ -43,7 +46,7 @@ Http::get('/hello-world') // Define Route

Http::setMode(Http::MODE_TYPE_PRODUCTION);

$http = new Http(new Server(), 'America/New_York');
$http = new Http(new Server(), 'America/New_York', $container);
$http->start();
Comment thread
ChiragAgg5k marked this conversation as resolved.
```

Expand All @@ -66,10 +69,13 @@ The library supports server adapters to be able to run on any PHP setup. You cou
#### Use PHP FPM server

```php
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\Http\Adapter\FPM\Server;

$container = new Container();

Http::get('/')
->inject('response')
->action(
Expand All @@ -78,7 +84,7 @@ Http::get('/')
}
);

$http = new Http(new Server(), 'America/New_York');
$http = new Http(new Server(), 'America/New_York', $container);
$http->start();
Comment thread
ChiragAgg5k marked this conversation as resolved.
```

Expand All @@ -87,11 +93,14 @@ $http->start();
#### Using Swoole server

```php
use Utopia\DI\Container;
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
use Utopia\Http\Adapter\Swoole\Server;

$container = new Container();

Http::get('/')
->inject('request')
->inject('response')
Expand All @@ -101,7 +110,7 @@ Http::get('/')
}
);

$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York');
$http = new Http(new Server('0.0.0.0', '80'), 'America/New_York', $container);
$http->start();
Comment thread
ChiragAgg5k marked this conversation as resolved.
```

Expand Down Expand Up @@ -210,17 +219,19 @@ Groups are designed to be actions that run during the lifecycle of requests to e

Resources allow you to prepare dependencies for requests such as database connection or the user who sent the request. A new instance of a resource is created for every request.

Define a resource:
Define a resource on the DI container:

```php
Http::setResource('timing', function() {
$container->setResource('timing', function() {
return \microtime(true);
});
```

Inject resource into endpoint action:

```php
$http = new Http(new Server(), 'America/New_York', $container);

Http::get('/')
->inject('timing')
->inject('response')
Expand Down Expand Up @@ -248,7 +259,7 @@ To learn more about architecture and features for this library, check out more i

## System Requirements

Utopia HTTP requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.
Utopia HTTP requires PHP 8.2 or later. We recommend using the latest PHP version whenever possible.

## More from Utopia

Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
],
"license": "MIT",
"minimum-stability": "stable",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/utopia-php/di"
}
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated
],
"autoload": {
"psr-4": {
"Utopia\\": "src/",
Expand All @@ -29,8 +35,9 @@
"bench": "vendor/bin/phpbench run --report=benchmark"
},
"require": {
"php": ">=8.0",
"php": ">=8.2",
"ext-swoole": "*",
"utopia-php/di": "dev-chore/extract-http-di-resources",
"utopia-php/validators": "0.2.*"
Comment thread
ChiragAgg5k marked this conversation as resolved.
Outdated
},
"require-dev": {
Expand Down
Loading
Loading