Chapters
26 Chapters
|
2:18:26
|
This course is archived!
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
24.
A Homepage for your API?
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"silex/silex": "~1.0", // v1.3.2
"symfony/twig-bridge": "~2.1", // v2.7.3
"symfony/security": "~2.4", // v2.7.3
"doctrine/dbal": "^2.5.4", // v2.5.4
"monolog/monolog": "~1.7.0", // 1.7.0
"symfony/validator": "~2.4", // v2.7.3
"symfony/expression-language": "~2.4", // v2.7.3
"jms/serializer": "~0.16", // 0.16.0
"willdurand/hateoas": "~2.3" // v2.3.0
},
"require-dev": {
"behat/mink": "~1.5", // v1.5.0
"behat/mink-goutte-driver": "~1.0.9", // v1.0.9
"behat/mink-selenium2-driver": "~1.1.1", // v1.1.1
"behat/behat": "~2.5", // v2.5.5
"behat/mink-extension": "~1.2.0", // v1.2.0
"phpunit/phpunit": "~5.7.0", // 5.7.27
"guzzle/guzzle": "~3.7" // v3.9.3
}
}
3 Comments
Hey folks, what is the purpose of hateoas and it's links? Can it be used to auto generate a graphQL schema? Do it have other uses? Because a Dev can simply look at the documentation to understand what endpoints to access.
And probably just as importantly: what situations is it unnessacary to add hateoas? For instance, if I'm the only consumer of the API and I'm already familiar with it, would it be nessacary to spend time to add hateoas?
Hey @cameron!
Excellent question :).
The long answer is that some people believe that these formats and links will become so standardized, that you could point an api client at the homepage of an api, and it would organically crawl the endpoints and follow the links until it found what it’s looking for (like a user browsing a web site).
But that’s a bit “science fiction” to me ;). Especially if you’re building an API for yourself.
But they are still really useful - especially the IRI links that api platform uses. Basically, I see links as a useful way to help pass more info to my javascript so that I don’t need to hardcode url patterns there. For example, if I make a GET request to /api/cheeses and then I want to fetch page 2 of the results, I don’t need to even care that we do this by adding ?page=2 (and that’s especially cool to not worry about if I already have other filters on the url like ?title=foo). Nope, I can just read the “next” link from the response and follow it. That’s not an “earth shatteringly cool thing”... but it *is* kinda nice.
The same is true for the IRI strings. If I fetch a cheese listing and I want more info about its owner, I know I can make a GET request to the owner IRI string to do that.
So... links are helpful! Done well, they make our life easier. But they’re not any crazy, magic solution.
Cheers!
Thanks. it would be good to have this context prior to beginning the "how to" component of hateoas.
"Houston: no signs of life"
Start the conversation!