Skip to content

Instantly share code, notes, and snippets.

@sungjaeHong
Last active August 28, 2017 07:11
Show Gist options
  • Save sungjaeHong/33f7a6998e7b5e658d3629314099ff36 to your computer and use it in GitHub Desktop.
Save sungjaeHong/33f7a6998e7b5e658d3629314099ff36 to your computer and use it in GitHub Desktop.
HATEOAS php parse
http://localhost:8080/contacts/pages?size=5&page=2
/*
{
"page": 2,
"message": null,
"status": "SUCCESS",
"errors": null,
"size": 5,
"content": [
{
"id": 11,
"firstname": "Fifi",
"lastname": "Duck",
"age": 8
},
{
"id": 12,
"firstname": "Loulou",
"lastname": "Duck",
"age": 8
}
],
"numberOfElements": 2,
"totalElements": 12,
"totalPages": 3,
"_links": {
"prev": {
"href": "http://localhost:8080/contacts/pages?size=5&page=1"
},
"first": {
"href": "http://localhost:8080/contacts/pages?size=5&page=0"
},
"last": {
"href": "http://localhost:8080/contacts/pages?size=5&page=2"
}
}
}
*/
<?php
include('./httpful.phar');
$uri = "http://localhost:8080/contacts/pages?page=1&size=5";
$response = \Httpful\Request::get($uri)->send();
$link = "_links";
echo ($response->body->$link->prev->href); // http://localhost:8080/contacts/pages?size=5&page=0
?>
//refer : http://phphttpclient.com/#h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment