You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/content-negotiation.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,12 @@
2
2
3
3
The API system has built-in [content negotiation](https://en.wikipedia.org/wiki/Content_negotiation) capabilities.
4
4
5
-
By default, only the [JSON-LD](https://json-ld.org)and JSON formats are enabled. However API Platform supports many more formats and can be extended.
5
+
By default, only the [JSON-LD](https://json-ld.org)format is enabled. However API Platform supports many more formats and can be extended.
6
6
7
7
The framework natively supports JSON-LD (and Hydra), GraphQL, JSON:API, HAL, YAML, CSV, HTML (API docs), raw JSON and raw XML.
8
8
Using the raw JSON or raw XML formats is discouraged, prefer using JSON-LD instead, which provides more feature and is as easy to use.
9
9
10
-
API Platform also supports [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) the JSON:API[`PATCH`](https://tools.ietf.org/html/rfc5789) formats, as well as [Problem Details (RFC 7807)](https://tools.ietf.org/html/rfc7807), Hydra and JSON:API error formats.
10
+
API Platform also supports [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) the JSON:API[`PATCH`](https://jsonapi.org/format/#crud-updating) formats, as well as [Problem Details (RFC 7807)](https://tools.ietf.org/html/rfc7807), [Hydra](https://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors) and [JSON:API](https://jsonapi.org/format/#errors) error formats.
11
11
12
12
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform/formats?cid=apip"><imgsrc="/docs/distribution/images/symfonycasts-player.png"alt="Formats screencast"><br>Watch the Formats screencast</a></p>
Copy file name to clipboardExpand all lines: core/deprecations.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ properties:
107
107
108
108
## Setting the `Sunset` HTTP Header to Indicate When a Resource or an Operation Will Be Removed
109
109
110
-
[The `Sunset` HTTP response header](https://tools.ietf.org/html/draft-wilde-sunset-header) indicates that a URI is likely to become unresponsive at a specified point in the future.
110
+
[The `Sunset` HTTP response header (RFC 8594)](https://www.rfc-editor.org/rfc/rfc8594) indicates that a URI is likely to become unresponsive at a specified point in the future.
111
111
It is especially useful to indicate when a deprecated URL will not be available anymore.
112
112
113
113
Thanks to the `sunset` attribute, API Platform makes it easy to set this header for all URLs related to a resource class:
Copy file name to clipboardExpand all lines: core/extensions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,8 @@ final readonly class CurrentUserExtension implements QueryCollectionExtensionInt
98
98
99
99
```
100
100
101
+
Note that the default `rootAlias` is "o" in the bundled `ItemProvider` and `CollectionProvider`, so you should use different aliases for your custom joins in your extension.
102
+
101
103
Finally, if you're not using the autoconfiguration, you have to register the custom extension with either of those tags:
Copy file name to clipboardExpand all lines: core/file-upload.md
+22-46Lines changed: 22 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,15 @@ before proceeding. It will help you get a grasp on how the bundle works, and why
11
11
**Note**: Uploading files won't work in `PUT` or `PATCH` requests, you must use `POST` method to upload files.
12
12
See [the related issue on Symfony](https://github.com/symfony/symfony/issues/9226) and [the related bug in PHP](https://bugs.php.net/bug.php?id=55815) talking about this behavior.
13
13
14
+
Enable the multipart format globally in order to use it as the input format of your resource:
15
+
16
+
```yaml
17
+
api_platform:
18
+
formats:
19
+
multipart: ['multipart/form-data']
20
+
jsonld: ['application/ld+json']
21
+
```
22
+
14
23
## Installing VichUploaderBundle
15
24
16
25
Install the bundle with the help of Composer:
@@ -44,9 +53,6 @@ In this example, we will create a `MediaObject` API resource. We will post files
44
53
to this resource endpoint, and then link the newly created resource to another
45
54
resource (in our case: `Book`).
46
55
47
-
This example will use a custom controller to receive the file.
48
-
The second example will use a custom `multipart/form-data` decoder to deserialize the resource instead.
49
-
50
56
### Configuring the Resource Receiving the Uploaded File
51
57
52
58
The `MediaObject` resource is implemented like this:
@@ -63,7 +69,7 @@ use ApiPlatform\Metadata\Get;
63
69
use ApiPlatform\Metadata\GetCollection;
64
70
use ApiPlatform\Metadata\Post;
65
71
use ApiPlatform\OpenApi\Model;
66
-
use App\Controller\CreateMediaObjectAction;
72
+
use App\State\SaveMediaObject;
67
73
use Doctrine\ORM\Mapping as ORM;
68
74
use Symfony\Component\HttpFoundation\File\File;
69
75
use Symfony\Component\Serializer\Annotation\Groups;
@@ -75,13 +81,12 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
At this point, the entity is configured, but we still need to write the action
131
-
that handles the file upload.
132
-
133
-
```php
134
-
<?php
135
-
// api/src/Controller/CreateMediaObjectAction.php
136
-
137
-
namespace App\Controller;
138
-
139
-
use App\Entity\MediaObject;
140
-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
141
-
use Symfony\Component\HttpFoundation\Request;
142
-
use Symfony\Component\HttpKernel\Attribute\AsController;
143
-
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
144
-
145
-
#[AsController]
146
-
final class CreateMediaObjectAction extends AbstractController
147
-
{
148
-
public function __invoke(Request $request): MediaObject
149
-
{
150
-
$uploadedFile = $request->files->get('file');
151
-
if (!$uploadedFile) {
152
-
throw new BadRequestHttpException('"file" is required');
153
-
}
154
-
155
-
$mediaObject = new MediaObject();
156
-
$mediaObject->file = $uploadedFile;
157
-
158
-
return $mediaObject;
159
-
}
160
-
}
161
-
```
133
+
Note: From V3.3 onwards, `'multipart/form-data'` must either be including in the global API-Platform config, either in `formats` or `defaults->inputFormats`, or defined as an `inputFormats` parameter on an operation by operation basis.
162
134
163
135
### Resolving the File URL
164
136
@@ -169,6 +141,7 @@ A [normalizer](serialization.md#normalization) could be used to set the `content
169
141
170
142
```php
171
143
<?php
144
+
// api/src/Serializer/MediaObjectNormalizer.php
172
145
173
146
namespace App\Serializer;
174
147
@@ -183,7 +156,7 @@ class MediaObjectNormalizer implements NormalizerInterface
0 commit comments