apigo/apigo (0.1.0.2)
Published 2025-08-19 12:09:05 +00:00 by noccy
Installation
{
"repositories": [{
"type": "composer",
"url": " "
}
]
}
composer require apigo/apigo:0.1.0.2
About this package
A framework for exposing APIs over HTTP
Apigo
like Amigo, but with a whole lot more APIs
Apigo is a framework built around autowiring and APIs. You can expose them as controllers, and your can call them as WebService
s.
When to use Apigo
- When you want neatly autowired services for controllers and logic, but you don't need the full Symfony stack.
- When all you want to do is accept requests and return JSON, immediatelly or deferred.
- When you need your application as a long-running process with timers and events.
You can think of Apigo as trying to bring some of the convenience we know and love from Symfony into ReactPHP. Autowiring in Symfony lets you create a new service by creating a new file. Apigo wants to provide similar comfort, but closer to bare metal.
Installing
$ composer require apigo/apigo
Using Apigo
- Apigo applications start at the
AbstractServer
class, so you should derive this into your application class. - The service container is built from the properties on your application class, so define your services and tag them with
#[Apigo\Apigo\Attributes\Service]
. - The controllers are also registered from application class properties, so go ahead and define your controllers and tag them with
#[Apigo\Apigo\Attributes\Controller]
. - Every method in registered controllers that is tagged with
#[Apigo\Apigo\Attributes\Http\Route]
will be exposed over HTTP. - Methods can be secured by providing the
requires
parameter on the#[Route]
. - You probably want to add a listening address, so override the
protected function init()
method in your application, and add a$this->addHttpListener("tcp://0.0.0.0:8000")
- Don't forget to call
start()
on your application.
Examples
namespace App;
use Apigo\Apigo\AbstractServer;
use Apigo\Apigo\Services\WebService;
class BookService extends WebService
{
public function findBook(string $name): PromiseInterface
{
return $this->call('/books/find', [ 'json' => [ 'name' => $name ]]);
}
}
class BookController
{
public function __construct(
private readonly BookService $bookService, // ← autowired
)
{
}
#[Route(path: "/book/{id}")]
public function getBook(string $id, Deferred $deferred): PromiseInterface
{
$this->bookService->findBook($query)->then(
);
return $deferred->promise();
}
}
class BookServer
{
#[Service]
public BookService $bookService;
#[Controller]
public BookController
$bookController;
}
$server = new BookServer();
$server->start();
Dependencies
Dependencies
ID | Version |
---|---|
league/container | ^5.1 |
league/flysystem | ^3.30 |
league/flysystem-local | ^3.30 |
league/flysystem-memory | ^3.29 |
psr/log | ^3.0 |
react/async | ^4.3 |
react/partial | ^3.0 |
react/react | ^1.4 |
Development Dependencies
ID | Version |
---|---|
phpstan/phpstan | ^2.1 |
twig/twig | ^3.21 |
Details
2025-08-19 12:09:05 +00:00
Assets (1)
Versions (3)
View all
Composer
1
Christopher Vagnetoft
GPL-2.0-or-later
30 KiB
apigo-apigo.0.1.0.2.zip
30 KiB