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.
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.
composer require ufo-tech/rpc-rest-adapterAfter 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).
RPC method:
user.getList
REST request:
GET /rest/users/
POST request with parameters:
POST /rest/user/getList
{
"page": 1,
"limit": 20
}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
}
}To expose methods in the public REST layer, the standard JsonRpcBundle access configuration is used, therefore the access control fully mirrors the RPC layer.
MIT © UFO-Tech