REST Bundle

REST Bundle

Version Downloads Stars

composer require ufo-tech/rest-bundle
  • PHP 8.4+
  • Symfony 7.2+ · 8
  • Built on JsonRpcBundle 10.4.3+
  • Protocol REST · OpenAPI · Postman
  • Type Symfony Bundle
  • Category API
  • License MIT

GitHub Packagist Changelog Known issues

A REST API on top of JsonRpcBundle methods for Symfony 7.2+ / 8 (PHP 8.4+).

The RPC method stays the only implementation: the Symfony #[Route] attribute on an RPC procedure method makes it available under its own path and HTTP method. Parameters, validation, security, cache, events and documentation come from the RPC core; the bundle adds HTTP routes, the REST request and response format, RFC 9457 errors and OpenAPI 3.1 and Postman documents.

This documentation describes version 1.3, which is not tagged yet (the latest release is 1.2.0). What appeared only in 1.3 is marked on the pages. See the Changelog.

From method to REST

Your code

use Symfony\Component\Routing\Attribute\Route;
use Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService;
use Ufo\RpcObject\RPC;

#[RPC\Info('catalog')]
#[Route('/catalog', name: 'catalog')]
class CatalogApi implements IRpcService
{
    #[Route('/items/{id}', name: 'item', methods: ['GET'])]
    public function item(int $id): array
    {
        return ['id' => $id, 'title' => 'Book'];
    }
}

Request

curl https://example.com/rest/catalog/items/42 \
  -H 'Ufo-RPC-Token: change-me'

Response 200

{"id": 42, "title": "Book"}

What you get without extra code:

  • GET /rest returns an OpenAPI 3.1 document with the catalog.item operation, and GET /rest/postman returns a Postman collection;
  • the value 42 from the path is cast to int according to the method signature (since 1.3);
  • errors are RFC 9457 problem details with an HTTP status (401, 404, 405, 422, …);
  • the same method is still available via JSON-RPC: POST /rpc with "method": "catalog.item".

Why REST Bundle

  • One implementation, two protocols. No REST controller per method, no second set of DTOs or separate validation. #[RPC\Assertions], #[RPC\Cache], #[RPC\Lock] and events work for REST the same way as for JSON-RPC.
  • Explicit publishing. Only a method with #[Route] gets into REST; the rest stay RPC-only (Routing).
  • API groups and versions. A separate REST entry point for each API group with its own methods, documentation and tokens; versions under /v2/....
  • Documentation from code. OpenAPI and Postman are built from the RPC service map: types, PHPDoc, @throws, translations (API documentation).
  • No separate configuration. The bundle uses the ufo_json_rpc settings: security, project name, translations (Configuration).

Version 1.2

Tag 1.2.0, 2026-10-16.

Key changes

  • Symfony 8 support: ^7.2|^8.0.
  • The Postman collection is built on the JsonRpcBundle AbstractPostmanAdapter: named REST: <project_name>, with a [group] suffix for a group other than general.
  • composer test and make test run PHPUnit.

What to keep in mind

  • Tools that look up the Postman collection by name will see the new name.

Environment changes

  • ufo-tech/json-rpc-bundle ^10.2.3.
  • Symfony ^7.2 or ^8.0.

Getting started

  1. Install the bundle: composer require ufo-tech/rest-bundle and a routes file.
  2. Add #[Route] to the methods you need (Routing) and open GET /rest.
  3. See how parameters are passed and how errors are returned.
  4. Set up security.

JSON-RPC batch, notifications and $rpc.callback are not available via REST: one HTTP request is one method call.

How the bundle works inside and how to extend it is described in the For developers section. When REST fits and when RPC does is covered in the article RPC, REST and GraphQL.