ufo-tech/rpc-rest-adapter

REST transport adapter for UFO-Tech json-rpc-bundle based applications.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:component

pkg:composer/ufo-tech/rpc-rest-adapter

1.0.0 2026-02-17 14:55 UTC

This package is auto-updated.

Last update: 2026-02-17 15:00:57 UTC


README

Ukraine

REST adapter for an RPC API based on JSON-RPC-BUNDLE

Adds support for a classic REST API on top of an existing RPC infrastructure.

🧬 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.

License Size package_version fork

Environment Requirements

php_version ufo-tech/rpc-bundle

⚙️ 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