I am building a RESTful API with Yii2 but have some questions in regards to HATEOAS support. Requests will output the pagination headers and include the HATEOAS header.
However the HATEOAS header contains all links as one long string. This is not very helpful for the consumer. Is this standard? Is there a way to change the format in Yii into something that is easier to handle?

Does the following look good?
"_links": {
"self": {
"href": "http://localhost/users?page=1"
},
"next": {
"href": "http://localhost/users?page=2"
},
"last": {
"href": "http://localhost/users?page=50"
}
}
If so, you can easily have links like that. Make sure your data model implements Linkable interface and then implement getLinks() method:
class User extends ActiveRecord implements Linkable
{
public function getLinks()
{
return [
Link::REL_SELF => Url::to(['user/view', 'id' => $this->id], true),
];
}
}
Serializer will automatically add "_links" to your response.
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With