API Platform supports the HAL format. When a
client sends a request with an Accept: application/hal+json header, API Platform serializes
responses following the HAL specification.
For details on enabling formats, see content negotiation.
The HAL entrypoint (GET /api/ with Accept: application/hal+json) lists the resources of your API
as links. For each resource, it exposes the URI of its collection under a relation named after the
short name of the resource.
Since API Platform 5.1, it also exposes an
URI template to reach one
item of the resource. The link has the same relation as the collection with an Item suffix, and is
flagged as templated:
{
"_links": {
"self": {
"href": "/api/"
},
"dummy": {
"href": "/api/dummies"
},
"dummyItem": {
"href": "/api/dummies/{id}",
"templated": true
}
}
}A HAL client expands the template with the identifier of the item. For example, with Traverson:
traverson
.from("https://example.com/api/")
.jsonHal()
.follow("dummyItem")
.withTemplateParameters({ id: 1 })
.getResource(callback);The template comes from the Get operation of the resource that has the fewest URI variables, so a
resource without such an operation has no Item link. Define the uriTemplate of this operation to
customize it. See operations.
You can also help us improve the documentation of this page.
Using an AI coding agent? See the documentation index for LLMs at /docs/llms.txt.
Made with love by
Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.
Learn more