Skip to content

Commit 3da7b10

Browse files
committed
creating_new_rest_resource.md: Complete TODOs
1 parent 4ef6d43 commit 3da7b10

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

docs/api/rest_api/extending_rest_api/creating_new_rest_resource.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,37 @@ services:
5151
[[= include_file('code_samples/api/rest_api/config/services.yaml', 36, 42) =]]
5252
```
5353

54-
Having the REST controllers set as services enables using features such as
54+
The [`controller.service_arguments` tag]([[= symfony_doc =]]/controller/service.html#using-the-controller-service-arguments-service-tag) declares the controller as a service receiving injections.
55+
It helps the autowiring of the serializer in the constructor.
5556

56-
- TODO: `controller.service_arguments`??
57-
- TODO: `ibexa.api_platform.resource` tag is needed to have the route available in live doc (/api/ibexa/v2/doc#/App/api_greet_get)
57+
The `ibexa.api_platform.resource` tag declares the service as an API Platform resource.
5858

5959
### Controller action
6060

6161
A REST controller should:
6262

63-
- return an object (passed automatically to a normaliser) or a `Response` (to customize it further)
64-
- TODO: extend `Ibexa\Rest\Server\Controller` to inherit utils methods and properties like `InputDispatcher` or `RequestParser`
63+
- return an object (passed automatically to a normalizer) or a `Response` (to customize it further)
64+
- extend `Ibexa\Rest\Server\Controller` to inherit useful methods and properties like `InputDispatcher` or `RequestParser`
6565

6666
``` php
6767
[[= include_file('code_samples/api/rest_api/src/Rest/Controller/DefaultController.php', 0, 14) =]]
6868
[[= include_file('code_samples/api/rest_api/src/Rest/Controller/DefaultController.php', 246) =]]
6969
```
7070

7171
<details>
72-
<summary>TODO</summary>
73-
74-
If the returned value was depending on a location, it could have been wrapped in a `CachedValue` to be cached by the reverse proxy (like Varnish) for future calls.
75-
76-
`CachedValue` is used in the following way:
77-
78-
```php
79-
return new CachedValue(
80-
new MyValue($args…),
81-
['locationId'=> $locationId]
82-
);
83-
```
84-
72+
<summary>HTTP Cache</summary>
73+
74+
If the returned value was depending on a location, it could have been wrapped in a <code>CachedValue</code>
75+
to be cached by the reverse proxy (like Varnish or Fastly) for future calls.
76+
77+
<code>CachedValue</code> is used as following:
78+
79+
``` php
80+
return new CachedValue(
81+
new MyValue($args…),
82+
['locationId'=> $locationId]
83+
);
84+
```
8585
</details>
8686

8787
## Value and Normalizer
@@ -162,19 +162,17 @@ Content-Type: application/vnd.ibexa.api.greeting+json
162162

163163
## Describe resource in OpenAPI schema
164164

165-
TODO
165+
Thanks to API Platform, you can document the OpenAPI resource directly from its controller through annotations.
166+
The resource is added to the OpenAPI Description dumped with `ibexa:openapi` command.
167+
In `dev` mode, the resource appears in the live documentation at `<dev-domain>/api/ibexa/v2/doc#/App/api_greet_get`.
166168

167-
```php
168-
[[= include_file('code_samples/api/rest_api/src/Rest/Controller/DefaultController.php', 0, 246) =]]
169+
``` php hl_lines="5 6 16 100"
170+
[[= include_file('code_samples/api/rest_api/src/Rest/Controller/DefaultController.php', 0, 247) =]]
171+
//…
169172
```
170173

171-
<details>
172-
<summary>
173-
174174
## Registering resources in REST root
175175

176-
</summary>
177-
178176
You can add the new resource to the [root resource](rest_api_usage.md#rest-root) through a configuration with the following pattern:
179177

180178
```yaml
@@ -192,7 +190,7 @@ The parameter values can be a real value or a placeholder.
192190
For example, `'router.generate("ibexa.rest.load_location", {locationPath: "1/2"})'` results in `/api/ibexa/v2/content/locations/1/2` while `'router.generate("ibexa.rest.load_location", {locationPath: "{locationPath}"})'` gives `/api/ibexa/v2/content/locations/{locationPath}`.
193191
This syntax is based on Symfony's [expression language]([[= symfony_doc =]]/components/expression_language/index.html), an extensible component that allows limited/readable scripting to be used outside the code context.
194192

195-
In this example, `app.rest.greeting` is available in every SiteAccess (`default`):
193+
In the following example, `app.rest.greeting` is available in every SiteAccess (`default`):
196194

197195
```yaml
198196
ibexa_rest:
@@ -204,12 +202,12 @@ ibexa_rest:
204202
href: 'router.generate("app.rest.greeting")'
205203
```
206204

207-
You can place this configuration in any regular config file, like the existing `config/packages/ibexa.yaml`, or a new `config/packages/ibexa_rest.yaml` file.
205+
You can place this configuration in any regular config file,
206+
like the existing `config/packages/ibexa.yaml`,
207+
or a new `config/packages/ibexa_rest.yaml` file.
208208

209-
The above example adds the following entry to the root XML output:
209+
This example adds the following entry to the root XML output:
210210

211211
```xml
212212
<greeting media-type="application/vnd.ibexa.api.Greeting+xml" href="/api/ibexa/v2/greet"/>
213213
```
214-
215-
</details>

0 commit comments

Comments
 (0)