ufo-tech / rest-bundle
REST API bundle for building RESTful services in the UFO-Tech ecosystem.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/ufo-tech/rest-bundle
Requires
- php: ^8.3
- cebe/php-openapi: ^1.8
- symfony/event-dispatcher: ^7.2
- ufo-tech/json-rpc-bundle: ^10.0
- ufo-tech/packages: ^1
Requires (Dev)
- phpunit/phpunit: ^11.0
- symfony/framework-bundle: ^7.2
- symfony/http-kernel: ^7.2
README
REST bundle for building RESTful services in the UFO-Tech ecosystem
Provides infrastructure for building REST APIs with a unified routing model, access control, and integration across UFO-Tech services.
🧬 Idea
This is an extension for JSON-RPC-BUNDLE that allows exposing a REST API based on the existing RPC infrastructure without additional configuration.
It enables fast deployment of an API layer only for the methods that must be available in the public API.
Environment Requirements
⚙️ Installation
composer require ufo-tech/rpc-rest-adapter
🚦 Quick Start
After installation, the adapter automatically registers a single REST entry point that proxies requests to RPC methods.
By default, the following endpoint is used:
/rest/{path}
where {path} is the RPC route (service/method).
📡 Request Example
RPC method:
user.getList
REST request:
GET /rest/users/
POST request with parameters:
POST /rest/user/getList { "page": 1, "limit": 20 }
⚙️ How it works
The adapter:
- receives an HTTP REST request
- transforms it into a JSON-RPC call
- forwards it to JsonRpcBundle
- returns a standard JSON response
No additional configuration is required. It is enough to add the #[Route] attribute to RPC services that must be available via the REST endpoint.
use Ufo\RpcObject\RPC; use Symfony\Component\Routing\Attribute\Route; #[RPC\Info(alias: 'User')] #[Route('/users', name: 'users')] class UserProcedure implements IRpcService { #[Route('/', name: 'create', methods: ['POST'])] public function create( #[RPC\Assertions([ new Assert\NotBlank(), ])] string $role, #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Regex( pattern: '/^\+380\d{9}$/', message: 'The phone number is not a valid UA mobile number' ), ])] string $phone, #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Length(min: 3), ])] string $firstName, #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Length(min: 3), ])] string $lastName, ): string { // create user } #[Route('/{userId}', name: 'update', methods: ['PUT'])] public function update( #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Uuid(), ])] string $userId, #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Length(min: 3), ])] string $firstName, #[RPC\Assertions([ new Assert\NotBlank(), new Assert\Length(min: 3), ])] string $lastName, ): string { // update user } }
🔐 Public API
To expose methods in the public REST layer, the standard JsonRpcBundle access configuration is used, therefore the access control fully mirrors the RPC layer.
🦠 License
MIT © UFO-Tech