Skip to content

Commit ac59baf

Browse files
authored
Merge pull request #658 from dunglas/sunset-header
Add docs for the Sunset HTTP header
2 parents ad5a148 + 0b2de51 commit ac59baf

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

core/deprecations.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,49 @@ class Review
9595
* With JSON-lD / Hydra, [an `owl:deprecated` annotation property](https://www.w3.org/TR/owl2-syntax/#Annotation_Properties) will be added to the appropriate data structure
9696
* With Swagger / OpenAPI, [a `deprecated` property](https://swagger.io/docs/specification/2-0/paths-and-operations/) will be added
9797
* With GraphQL, the [`isDeprecated` and `deprecationReason` properties](https://facebook.github.io/graphql/June2018/#sec-Deprecation) will be added to the schema
98+
99+
## Setting the `Sunset` HTTP Header to Indicate When a Resource or an Operation Will Be Removed
100+
101+
[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.
102+
It is especially useful to indicate when a deprecated URL will not be available anymore.
103+
104+
Thanks to the `sunset` attribute, API Platform makes it easy to set this header for all URLs related to a resource class:
105+
106+
```php
107+
<?php
108+
// api/src/Entity/Parchment.php
109+
110+
/**
111+
* @ApiResource(
112+
* deprecationReason="Create a Book instead",
113+
* sunset="01/01/2020"
114+
* )
115+
*/
116+
class Parchment
117+
{
118+
// ...
119+
}
120+
```
121+
122+
The value of the `sunset` attribute can be any string compatible with [the `\DateTime` constructor](http://php.net/manual/en/datetime.construct.php).
123+
It will be automatically converted to a valid HTTP date.
124+
125+
It's also possible to set the `Sunset` header only for a specific [operation](operations.md):
126+
127+
```php
128+
<?php
129+
// api/src/Entity/Parchment.php
130+
131+
/**
132+
* @ApiResource(itemOperations={
133+
* "get"={
134+
* "deprecation_reason"="Retrieve a Book instead",
135+
* "sunset"="01/01/2020"
136+
* }
137+
* })
138+
*/
139+
class Parchment
140+
{
141+
// ...
142+
}
143+
```

0 commit comments

Comments
 (0)