diff --git a/docs/adr/0000-subresources-definition.md b/docs/adr/0000-subresources-definition.md index 72cccb17e03..062711279fe 100644 --- a/docs/adr/0000-subresources-definition.md +++ b/docs/adr/0000-subresources-definition.md @@ -1,6 +1,6 @@ # Subresource Definition -* Status: proposed +* Status: superseded by [0002-resource-definition](0002-resource-definition.md)] * Deciders: @dunglas, @vincentchalamon, @soyuka, @GregoireHebert, @Deuchnord ## Context and Problem Statement diff --git a/docs/adr/0002-resource-definition.md b/docs/adr/0002-resource-definition.md new file mode 100644 index 00000000000..e6e564731ea --- /dev/null +++ b/docs/adr/0002-resource-definition.md @@ -0,0 +1,205 @@ +# Resource definition + +* Status: proposed +* Deciders: @dunglas @soyuka @vincentchalamon @GregoireHebert + +## Context and Problem Statement + +The API Platform `@ApiResource` annotation was initially created to represent a Resource as defined in [Roy Fiedling's dissertation about REST](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_2_1_1) in corelation with [RFC 7231 about HTTP Semantics](https://httpwg.org/specs/rfc7231.html#resources). This annotation brings some confusion as it mixes concepts of resources and operations. Here we discussed how we could revamp API Platform's resource definition using PHP8 attributes, beeing as close as we can to Roy Fiedling's thesis vocabulary. + +## Considered Options + +* Declare multiple ApiResource on a PHP Class [see Subresources definition](./0000-subresources-definition.md) +* Declare operations in conjunction with resources using two attributes: `Resource` and `Operation` +* Use HTTP Verb to represent operations with a syntax sugar for collections (`CGET`?) + +## Decision Outcome + +As Roy Fiedling's thesis states: + +> REST uses a resource identifier to identify the particular resource involved in an interaction between components. REST connectors provide a generic interface for accessing and manipulating the value set of a resource, regardless of how the membership function is defined or the type of software that is handling the request. + +In API Platform, this resource identifier is also named [IRI (Internationalized Resource Identifiers)](https://tools.ietf.org/html/rfc3987). Following these recommandation, applied to PHP, we came up with the following [PHP 8 attributes](https://www.php.net/manual/en/language.attributes.php): + +```php + + + + Code + + + Operations + + + + +
+#[Get]
+class User {}
+            
+ + + + + + + +
+#[GetCollection]
+class User {}
+            
+ + + + + + + +
+#[Get("/users")]
+class User {}
+            
+ + + + + + + +
+#[Post("/users")]
+#[Patch("/users/{id}")]
+class User {}
+            
+ + +