Skip to content

Commit b34a7a6

Browse files
authored
Document Deprecation HTTP Header usage
Added guidance on setting the Deprecation HTTP header, including examples and usage of the deprecation header and deprecation link.
1 parent 17aac72 commit b34a7a6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/deprecations.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,40 @@ class Parchment
169169
}
170170
```
171171

172+
### Setting the Deprecation HTTP Header to Indicate When an Operation Is Deprecated
173+
174+
[The Deprecation HTTP Response Header Field (RFC 9745)](https://datatracker.ietf.org/doc/rfc9745/) indicates that a URI
175+
will be or has been deprecated. This header can be used alongside the `Sunset` header to provide a deprecation date and
176+
a link to relevant documentation. Additionally, the `deprecation` link relation can be used to point to a resource that
177+
provides further information about the planned or existing deprecation.
178+
179+
To set a `Deprecation` header, use the `headers` option in the operation definition. The value of the `deprecation`
180+
header should be a Unix timestamp. You can also provide a `Link` header with a `deprecation` relation to give users more
181+
context about the deprecation:
182+
183+
```php
184+
use ApiPlatform\Metadata\ApiResource;
185+
use ApiPlatform\Metadata\GetCollection;
186+
use ApiPlatform\Metadata\Link;
187+
188+
#[ApiResource(
189+
operations: [
190+
new GetCollection(
191+
headers: [
192+
'deprecation' => '@1688169599', // Unix timestamp
193+
],
194+
links: [
195+
new Link('deprecation', 'https://developer.example.com/deprecation'),
196+
],
197+
),
198+
],
199+
)]
200+
class DeprecationHeader
201+
{
202+
// ...
203+
}
204+
```
205+
172206
## Path versioning
173207

174208
> [!NOTE] REST and GraphQL architectures recommend to use deprecations instead of path versioning.

0 commit comments

Comments
 (0)