REST Bundle

← REST Bundle

Ashterix

docs: rewrite JsonRpcBundle docs, add SDK docs, move them under docs/api

en/docs/api/rest-bundle/README.md new file +83 āˆ’0

1 + # REST Bundle
2 +
3 + :::block class="floatinginfobox"
4 + <include>(docs/api/rest-bundle/.info.md)
5 + :::
6 +
7 + A REST API on top of [JsonRpcBundle](/docs/api/json-rpc-bundle) methods for Symfony 7.2+ / 8 (PHP 8.4+).
8 +
9 + 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.
10 +
11 + :::info
12 + 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](/docs/api/rest-bundle/change_log).
13 + :::
14 +
15 + ## From method to REST
16 +
17 + ::::columns
18 + :::col
19 + **Your code**
20 +
21 + ```php
22 + use Symfony\Component\Routing\Attribute\Route;
23 + use Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService;
24 + use Ufo\RpcObject\RPC;
25 +
26 + #[RPC\Info('catalog')]
27 + #[Route('/catalog', name: 'catalog')]
28 + class CatalogApi implements IRpcService
29 + {
30 + #[Route('/items/{id}', name: 'item', methods: ['GET'])]
31 + public function item(int $id): array
32 + {
33 + return ['id' => $id, 'title' => 'Book'];
34 + }
35 + }
36 + ```
37 + :::
38 +
39 + :::col
40 + **Request**
41 +
42 + ```bash
43 + curl https://example.com/rest/catalog/items/42 \
44 + -H 'Ufo-RPC-Token: change-me'
45 + ```
46 +
47 + **Response** `200`
48 +
49 + ```json
50 + {"id": 42, "title": "Book"}
51 + ```
52 + :::
53 + ::::
54 +
55 + What you get without extra code:
56 +
57 + * `GET /rest` returns an OpenAPI 3.1 document with the `catalog.item` operation, and `GET /rest/postman` returns a Postman collection;
58 + * the value `42` from the path is cast to `int` according to the method signature (since 1.3);
59 + * errors are RFC 9457 problem details with an HTTP status (`401`, `404`, `405`, `422`, …);
60 + * the same method is still available via JSON-RPC: `POST /rpc` with `"method": "catalog.item"`.
61 +
62 + ## Why REST Bundle
63 +
64 + * **One implementation, two protocols.** No REST controller per method, no second set of DTOs or separate validation. [`#[RPC\Assertions]`](/docs/api/json-rpc-bundle/add_rpc_service/assertions), [`#[RPC\Cache]`](/docs/api/json-rpc-bundle/add_rpc_service/cache), [`#[RPC\Lock]`](/docs/api/json-rpc-bundle/add_rpc_service/lock) and [events](/docs/api/json-rpc-bundle/functionality/events) work for REST the same way as for JSON-RPC.
65 + * **Explicit publishing.** Only a method with `#[Route]` gets into REST; the rest stay RPC-only ([Routing](/docs/api/rest-bundle/routing)).
66 + * **API groups and versions.** A separate REST entry point for each [API group](/docs/api/json-rpc-bundle/functionality/groups) with its own methods, documentation and tokens; [versions](/docs/api/json-rpc-bundle/functionality/versions) under `/v2/...`.
67 + * **Documentation from code.** OpenAPI and Postman are built from the RPC service map: types, PHPDoc, `@throws`, translations ([API documentation](/docs/api/rest-bundle/documentation)).
68 + * **No separate configuration.** The bundle uses the `ufo_json_rpc` settings: security, project name, translations ([Configuration](/docs/api/rest-bundle/config)).
69 +
70 + :::info
71 + <include>(change_log/latest.md)
72 + :::
73 +
74 + ## Getting started
75 +
76 + 1. [Install the bundle](/docs/api/rest-bundle/installation): `composer require ufo-tech/rest-bundle` and a routes file.
77 + 2. Add `#[Route]` to the methods you need ([Routing](/docs/api/rest-bundle/routing)) and open `GET /rest`.
78 + 3. See how [parameters are passed](/docs/api/rest-bundle/requests) and how [errors are returned](/docs/api/rest-bundle/error_handling).
79 + 4. Set up [security](/docs/api/rest-bundle/security).
80 +
81 + JSON-RPC batch, notifications and `$rpc.callback` are not available via REST: one HTTP request is one method call.
82 +
83 + How the bundle works inside and how to extend it is described in the [For developers](/docs/api/rest-bundle/developers) section. When REST fits and when RPC does is covered in the article [RPC, REST and GraphQL](/articles/api/rpc_vs_rest_vs_graphql).

en/docs/api/rest-bundle/.info.md new file +65 āˆ’0

1 + :::::columns border="1" zebra="1"
2 + ::::row
3 + :::col width="40%"
4 + Download
5 + :::
6 +
7 + :::col
8 + [Packagist](https://packagist.org/packages/ufo-tech/rest-bundle)<br>
9 + [GitHub](https://github.com/UFO-Tech/rest-bundle)
10 + :::
11 + ::::
12 +
13 + ::::row
14 + :::col width="40%"
15 + Current version
16 + :::
17 +
18 + :::col
19 + [![](https://img.shields.io/github/v/tag/ufo-tech/rest-bundle?color=blue&label=&logo=Packagist&logoColor=white&labelColor=7b8185)](https://packagist.org/packages/ufo-tech/rest-bundle)
20 + :::
21 + ::::
22 +
23 + ::::row
24 + :::col width="40%"
25 + Category
26 + :::
27 +
28 + :::col
29 + API
30 + :::
31 + ::::
32 +
33 + ::::row
34 + :::col width="40%"
35 + Type
36 + :::
37 +
38 + :::col
39 + Symfony Bundle
40 + :::
41 + ::::
42 +
43 + ::::row
44 + :::col width="40%"
45 + Dependencies
46 + :::
47 +
48 + :::col
49 + ![php_version](https://img.shields.io/packagist/dependency-v/ufo-tech/rest-bundle/php?logo=PHP&logoColor=white)
50 + ![json_rpc_bundle](https://img.shields.io/packagist/dependency-v/ufo-tech/rest-bundle/ufo-tech/json-rpc-bundle?label=JsonRpcBundle&logoColor=white)
51 + :::
52 + ::::
53 +
54 + ::::row
55 + :::col width="40%"
56 + Other details
57 + :::
58 +
59 + :::col
60 + ![License](https://img.shields.io/badge/license-MIT-green?labelColor=7b8185)
61 + ![Size](https://img.shields.io/github/repo-size/ufo-tech/rest-bundle?label=Size%20of%20the%20repository)
62 + ![fork](https://img.shields.io/github/forks/ufo-tech/rest-bundle?color=green&logo=github&style=flat)
63 + :::
64 + ::::
65 + :::::

en/docs/api/rest-bundle/change_log/latest.md new file +1 āˆ’0

1 + <include>(1.2.md)

en/docs/api/rest-bundle/change_log/1.2.md new file +18 āˆ’0

1 + ## Version 1.2
2 +
3 + Tag 1.2.0, 2026-10-16.
4 +
5 + ### Key changes
6 +
7 + * Symfony 8 support: `^7.2|^8.0`.
8 + * The Postman collection is built on the JsonRpcBundle `AbstractPostmanAdapter`: named `REST: <project_name>`, with a ` [group]` suffix for a group other than `general`.
9 + * `composer test` and `make test` run PHPUnit.
10 +
11 + ### What to keep in mind
12 +
13 + * Tools that look up the Postman collection by name will see the new name.
14 +
15 + ### Environment changes
16 +
17 + * `ufo-tech/json-rpc-bundle` ^10.2.3.
18 + * Symfony ^7.2 or ^8.0.