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!
01.
The Serializer: Swiss-Army Knife of APIs
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!
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
}
}
12 Comments
no video download?
Hey!
This is taking a bit longer (biggest screencast ever for us), which is why we released without the video download. But we're encoding things right now - the download should be available on a day or 2 :).
Cheers!
Hi! I'm guetting this error when I try to access localhost:8000 :
Fatal error: Uncaught UnexpectedValueException: The stream or file "C:\xampp\htdocs\rest-ep2\src\KnpU\CodeBattle/../../../logs/development.log" could not be opened: failed to open stream: No such file or directory in C:\xampp\htdocs\rest-ep2\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php:70 Stack trace: #0 C:\xampp\htdocs\rest-ep2\vendor\monolog\monolog\src\Monolog\Handler\AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array) #1 C:\xampp\htdocs\rest-ep2\vendor\monolog\monolog\src\Monolog\Logger.php(244): Monolog\Handler\AbstractProcessingHandler->handle(Array) #2 C:\xampp\htdocs\rest-ep2\vendor\monolog\monolog\src\Monolog\Logger.php(320): Monolog\Logger->addRecord(500, 'UnexpectedValue...', Array) #3 C:\xampp\htdocs\rest-ep2\vendor\silex\silex\src\Silex\Provider\MonologServiceProvider.php(83): Monolog\Logger->addCritical('UnexpectedValue...', Array) #4 [internal function]: Silex\Provider\MonologServiceProvider->Silex\Provider\{closure}(Object(UnexpectedValueException), 500) #5 C:\xam in C:\xampp\htdocs\rest-ep2\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php on line 70I'm on Windows 10 and I already ran composer install. What can I do to make the project work?
Hey @Quentin!
Hmm, sorry about the problem! I'm not sure why Monolog is angry, but the solution *could* be as easy as this (so let's try the easy solution first!): create a new "logs" directory at the root of your project (so, put this "logs" directory in the same directory as the "src" directory).
Let me know if this fixes it - it works for us, but it could be something that's affecting Windows for some reason. If this *does* fix it, we can add that directory to the code download so that it's always there :).
Cheers!
Yep, fixed it! Thank you!
Hi!
I don't seem to find the download link to the project files anywhere ...
https://github.com/knpunive... is the right one?
And if yes: Trying to log into the application, i get an SQL error.
Additionally, i see that your jQuery dependency from code.google.com ain't available anymore.
Would be terrific if the code to the course could be reviewed and updated.
Thanks alot from Salzburg, Austria!
Hey Jjarolim,
See the big orange button in the right top corner of any video page called "Download" :) When you hover over it - you will see "Course Code" button to download start and finish course code. Here's a screenshot of this button: https://imgur.com/a/0mpMTuC
The correct repository behind this course is: https://github.com/knpunive...
> And if yes: Trying to log into the application, i get an SQL error
Before running the project you need to perform a few simple steps, like install composer, create DB, create schema, etc. All the required steps and their correct order you can find in README file located in downloaded code. Difficult to say something more about it without seeing the exact error.
I also just downloaded source code and double-checked the homepage - no JS errors for me, both links work for me:
http://code.jquery.com/jque...
http://netdna.bootstrapcdn....
Cheers!
Hi Ryan! I hope i'm not being boring...
But I cloned the repository ( https://github.com/knpuniversity/rest-ep2/ ) and ran the tests with Behat, and got not only one error, but three. To solve the 2 errors I have to do this:
### Application ###
### programmer.feature ###
So, i have to add the reference: https://github.com/knpuniversity/rest/blob/master/features/api/ApiFeatureContext.php#L262
Hey!
Sorry - I missed this message! If you download the code from the repository, you get the starting code at the beginning of episode *1*. To get the code at the start of episode 2, you'll need to download it from this page (which is only available now to subscribers). I just downloaded the starting code for episode 2 and all of the tests pass - without making these changes. The changes you listed above *are* correct, but they're included in the starting episode 2 code download (since we made those changes near the end of episode 1.
And no worries - I like hearing about potential bugs in the tutorial - we want them to be clear for everyone!
Cheers!
Hey Ryan! I have a question. We have this CRUD operations, which are great, but what if I have a quiz and I need and entry point for answering the question? What should my route look like? What my representation (json) should look like? If I have a table answer_user, should I create a controller UserAnswersController and put crud operations there?
By now I have an action in QuestionsController called answer that contains all this logic of updtaing answer_user table.
Hey 3amprogrammer!
Oh man, this type of question was one of the *hardest* things for me to really understand with REST. So, it's a great question :). But mostly, the answer is: it doesn't matter. Do your best to think of what makes sense, implement it, and never look back.
Now, let's look at your situation. Probably, you will have some GET endpoint to return the details of a specific question, e.g.:
GET /questions/{id}
Thinking philosophically, to answer this question, you're not "modifying" the question. So, a simple PUT to this URL doesn't make sense. Next, can we think of the "answers" as its own resource? If so, then, even if we don't *need* this endpoint, it should make sense to be able to make a GET request to /question/{id}/answers to return *all* answers to this question. And yes, I think, philosophically, that makes some sense :).
So, I would do this:
POST /questions/{id}/answers
But, if you don't think it makes sense that a "user answer" is its own resource, and rather, that "answering a question" is more of an "action", then this route starts to fall apart and not really fit cleanly into REST. And that's ok! Sometimes, you have an endpoint that is just awkward for REST. In those cases, I recommend making a POST request to the resource (i.e. /questions/{id}) with a URL fragment at the end that describes the "action" being taken. So:
POST /questions/{id}}/answer
I talk about these "weird" endpoints here: https://knpuniversity.com/s... and here: https://knpuniversity.com/s...
As far as a controller, I would probably put it into QuestionController, but if there were a few endpoints related to user answers, I then might create a separate UserAnswerController.
Let me know if this helped - sorry for the slow reply this time :)
When is going to be possible to download videos of this screencast series?
"Houston: no signs of life"
Start the conversation!