Skip to content

Commit f03dff5

Browse files
authored
Create README.md
1 parent de1080b commit f03dff5

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# API Platform extensions bundle
2+
What is API Platform and how do we extend it?
3+
4+
# Filters
5+
These filters are added by this bundle:
6+
7+
## GlobalSearchFilter (`api_platform.doctrine.orm.global_search_filter`)
8+
Searches (recursively?) through the specified columns (or all of them, scary stuff) of an entity on whose endpoint it's activated.
9+
10+
Configure the filter as a service (`config/services/api_platform/search/[$domain/]$entity.yaml`):
11+
```yaml
12+
services:
13+
api.resource.region.global.search_filter:
14+
parent: 'api_platform.doctrine.orm.global_search_filter'
15+
arguments: [ {
16+
'name': 'partial',
17+
'depot.description': 'partial',
18+
} ]
19+
tags: [ { name: 'api_platform.filter', id: 'api.region.global_search_filter' } ]
20+
autowire: false
21+
autoconfigure: false
22+
```
23+
24+
And apply it to the appropriate resource:
25+
```yaml
26+
App\Entity\Transport\Region:
27+
attributes:
28+
route_prefix: /transport
29+
filters:
30+
- 'api.region.global_search_filter'
31+
```
32+
33+
Now when a user calls the API with ?search=foo, the query will become something like this:
34+
35+
```sql
36+
SELECT
37+
r.*
38+
FROM
39+
region r
40+
LEFT JOIN
41+
depot d
42+
ON
43+
d.id = r.depot_id
44+
WHERE
45+
r.name LIKE '%foo%'
46+
OR d.description LIKE '%foo%'
47+
```
48+
49+
## OrSearchFilter (`api_platform.doctrine.orm.or_search_filter`)
50+
TODO
51+
52+
## UuidFilter (`api_platform.doctrine.orm.uuid_filter`)
53+
For looking up nested entities by their UUID, because API Platform doesn't support that (see https://github.com/api-platform/core/pull/3774, was reverted because it broke date search).
54+
55+
Service configuration:
56+
```yaml
57+
services:
58+
api.resource.transport_position.vehicle_filter:
59+
parent: 'api_platform.doctrine.orm.uuid_filter'
60+
arguments: [ {
61+
vehicle.id: 'exact'
62+
} ]
63+
tags: [ { name: 'api_platform.filter', id: 'api.transport_position.vehicle_filter' } ]
64+
autowire: false
65+
autoconfigure: false
66+
public: false
67+
```
68+
69+
API Platform entity configuration:
70+
```yaml
71+
App\Entity\Transport\Position:
72+
collectionOperations:
73+
get:
74+
filters:
75+
- 'api.transport_position.vehicle_filter'
76+
```
77+
78+
Now the API caller can filter using `GET .../transport_positions?vehicle.id=$uuid`.
79+
80+
# Routes
81+
The bundle introduces the following route(s):
82+
83+
## `/me`
84+
Get info about the caller. Includes a SwaggerDecorator to generate OpenAPI documentation about this endpoint.

0 commit comments

Comments
 (0)