core
core copied to clipboard
Support for the Link-Template HTTP Header Field (RFC 9652)
Hello,
I recently came across RFC 9652, which introduces the Link-Template HTTP header field. This header allows describing the structure of a link between resources using URI templates, making it possible to generate new links dynamically.
While exploring this idea, I noticed that API Platform already supports the itemUriTemplate property for the PHP Post attribute. This property could serve as an excellent starting point for implementing Link-Template, and perhaps the concept of URI templates could be generalized to all operations. Additionally, the inclusion of parameters as defined in the RFC could make this feature even more powerful.
Example:
For a resource /books/{book_id}, API Platform could emit a header like this:
Link-Template: "/books/{book_id}/author"; rel="author"; anchor="#{book_id}"
This would indicate to clients how to construct links to an author resource dynamically based on a book's ID.
❓ Question: Would this feature align with the project's long-term goals?
Good idea! PR welcome
Fine, I will take the time to implement it.
However, the first step might be to update the symfony/web-link component.
I noticed references to RFC5988, but it has been superseded by RFC8288.
This is a good opportunity to update the Link class or the listener if necessary.
Note that the code is at: https://github.com/api-platform/core/blob/main/src/State/Processor/AddLinkHeaderProcessor.php