In this series we are going to take most of what has been taught on CodeReviewVideos so far, and use it to implement the foundation of a Symfony-based RESTful API.
This is not a good starting point if you have never used Symfony before. If you are a beginner, please try the Symfony Tutorial for Beginners before attempting to create a RESTful API.
Whilst very new, we are going to proceed with Symfony 3 for this project. However, if you are still using Symfony 2, you should have no trouble following along. If anything, your life may be that little bit easier ;)
By the end of this series you will have created a RESTful API with FOSRESTBundle, guided by tests using Behat 3 and PHPSpec 2. The API itself will exposes Users - via FOSUserBundle - along with Accounts, and File Uploading using Flysystem.
You will have gained an understanding into how to add further 'modules' to your API, allowing you to create custom end points to meet the needs of your specific application.
As with many things Symfony, there are multiple ways to achieve the goals in this series. We could switch out FOSRESTBundle for DunglasAPIBundle. We could switch Flysystem for Guafrette. You are entirely free to do so.
This API is going to be based on FOSRESTBundle. The main reasoning for this is that I have already covered this bundle in another dedicated tutorial series, so if you get stuck, there are plenty of lessons explaining the general setup.
You may be wondering about the difference between a User and an Account. The idea here is that every User would have their own User Profile, but may belong to one of more Accounts. This is pretty helpful in the real world, and opens up options for your app as it grows. Feel free to rip this part out if you don't need it.
Log in is going to be a little different here. When a User POST's in a valid username and password combo, they will receive a JSON Web Token / JWT (pronounced Jot), which they will then need to use as part of any future request. Don't worry, we will cover this in full, and you will see it's really not that difficult at all. The reasoning for doing this is that our front end will thank us for it.
To ensure stability, we will be using VirtualBox with an Ansible build script. This will - hopefully - mean getting from development to production is largely taken care of.
Hopefully you will find this exercise useful and practical. Please feel free to leave comments, ask questions, or get in touch if you would like to know more about a specific topic.
|2||Setting Up Our Development Environment||05:08|
|3||Installing Symfony 3, Behat, and more||13:53|
|4||User Feature - Part 1||17:47|
|5||User Feature - Part 2||07:51|
|6||Talking English To Your Computer||11:05|
|7||Teaching Your Database To Forget||07:42|
|8||Creating User Data From Behat Background - Part 1||14:44|
|9||Creating User Data From Behat Background - Part 2||11:33|
|10||Creating A Custom RestApiContext||17:44|
|11||Our First Passing Behat User Scenario||12:01|
|12||Our Next Passing Step||13:10|
|13||Securing Our User Endpoint - Part 1||17:17|
|14||Securing Our User Endpoint - Part 2||24:27|
|15||Securing Our User Endpoint - Part 3||24:47|
|16||Log In To A Symfony API With JWTs (LexikJWTAuthenticationBundle)||11:02|
|17||Implementing PATCH for Users||18:17|
|18||Improving our API User Experience||13:59|
|19||GET a Collection of Accounts||12:15|
|20||POSTing in New Accounts||14:34|
|21||PUT and PATCH for Accounts||12:14|
|22||How To DELETE Existing Accounts||05:11|
|23||File Feature Overview||11:40|
|24||File - Using Existing Resources as Boilerplate||15:17|
|26||Fixing A Bug In POST Guided By Behat||12:50|
|27||Wrapping Up With File DELETE||07:47|
If you have found this course helpful, please share it.