RESTful API With PHP & MySQL
HTML-код
- Опубликовано: 14 дек 2016
- In this video we will build a complete JSON RESTful API using PHP and MySQL. We will use the SlimPHP framework along with PDO to interact with the MySQL database.
CODE -github.com/bradtraversy/slimapp
RELATED COURSE - www.traversymedia.com/course/l...
SlimPHP Site - www.slimframework.com/
Get Composer - getcomposer.org/ - Наука
This is my own opinion and I don't care if somebody disagrees! But you are by far the best teacher! Other instructors are not even close to you. Not even close. Thanks a lot Brad!
One thing I really like about this tutorial is unlike other it does not cut out the errors and mistakes he made. Which saves a lot of scratches in your head when you stumble upon it.
Dude, you don't know how long I have been searching for this. People seem to think the information is out there about making a web API that returns JSON - but nobody shows it end to end. I.e. they show how to do a flavour on local host, but nothing about actually deploying it to server to make it useful. Thanks so so so much!
I needed a quick run down of slim as an api. This was exactly what I needed. From one YT Creator to another. Big thank you!
Great tutorial! It helped a lot! Thanks!! I have always confused about the "Restful" concept and the full process between the front end and the back end. This video makes it crystal clear to me!
Cheers man. I learned from your nodejs tutorials and now PHP 🙏
Nice tutorial, exactly what I needed for weeks. Thumbs up!
Great Tutorial. I thank you for leaving the issues you had it. I think Its good to see what problems can appear in real world. Great job!!
Thank you so much for spend so much time doing this video! Was really helpful for me!
Thanks! Nicely done. Really useful.I like the way you go from the very beginning.
This was a big help in putting a few concepts into perspective. Thank you.
Great Tutorial Brad, simple and useful just what i needed.
Awesome instructor, your videos are the best!!!! Thanks!
Another great video. Fits in well with a current project.
Thank you, this was exactly what I need for my project...
I start learning programming by your udemy angular course , and here you are helping me to learn rest api in php and node both thanks a lot :)
One of the best video on REST FULL API
Even my grand ma would understand your explanations! Thanks a lot. You are great!
Thank you very much! You saved tons of time for me. Great tutorial!
Excellent tutorial! :) Congrats and thank you for sharing your knowledge!
just like facebook added some many emoticons to express how much a person can appreciate a post either with the 'like', 'love' buttons and all, i wish youtube has such features cos i really do love your tutorials mehn !!! ...God has gifted you in the art of making programming easy and understandable to guys like me _much appreciated Brad Traversy.
Great video! was looking for such video since very long and ur video is to the point and easy to understand.
Excellent tutorial! Thank you! It helped me a lot!
My inner OCD was going nuts with the missing dollar sign on mysql_connect_str and I was starting to question my knowledge of PHP thank god for 29.30
Amazing tutorial! Thank you Travis!
Thank you for sharing this with us! Amazing tutorial!
Awesome tutorial ! Thank you Brad !
Thanks for this, this was my first time doing a CRUD based API in slim. :)
Excellent work, man!
That is a very useful and very well prepared tutorial! Thanks! :)
Nicely Explained Tutorial!! Thanks for the efforts!! Keep up the good work!! Cheers!!
Thanks a ton! you saved my day! it really helps me to write back-end code as i am Android Dev. thanks again!
You and me both brother
Wow It works! I can't believe I've done it! Thank you for this - I'm mostly doing this to get up and running with the vue.js frontend but doing this was pretty cool!
Solid training Video!
Claps claps clsps 👏👏👏 bilions of claps for you Brad for making this. This one video is the answer of my 2 weeks headache. I am so thankful to you. World is grest because of the prople like you Brad.
I followed along with this but did it in Laravel so I could get to work on the Front End part of this project. Thank you for introducing me to SlimPHP though, I can see that I will use it for simple PHP tasks where a framework like Laravel is overkill.
Excellent explanation, thank you very much! :D
Very clear and concise ,Thank you
Very useful tutorial. Thanks for posting. Looking forward to your Vue,js frontend tut.
You gave me hope! Was about to give up all this web stuff for good like I did a couple of years back. Your simple approach and explaining made me want to learn and believe in myself. Thanks man!
It took me like 4 attempts to actually use this to make a persistent server in UE4
@@dislikecounter6392 that is why I am never giving up on learning again. Imagine if you gave up on the first attempt?
@@SimPwear84 I took a break for a few days and worked on other PHP tutorials like outputting a JSON and such lol then came back to this after I understood PHP a little better.
Sometimes all ya need to do is take a step back.
@@dislikecounter6392 Breaks are always good. Highly recommended
good video! i just set it up and everything worked as you said in the video! thanks
Thanks always Traversy Media...
It is a genuinely exellent video. Thank you
Best Video ever!! Thank you so much! I try now to create a ReactJS Frontend ;)
Awesome bro. Thankyou. I might use this with react.
Great tutorial. Let's do the VueJS frontend to this api. I will give a try) thanks.
Good Call! Ill see what I can do
Wow, you read my mind, I'm currently writing a webapp with a Slim3 rest api for my backend and Vue2 as my frontend framework... Both frameworks have pretty tiny footprints and are a joy to work with
Nice tutorial grabbed to essentials off it but made my own with eloquent ORM instead bc it's so much easier to use then PDO.
Great video, the only issue I found using postman was that the headers were set to text/html. This was a problem for me developing a WPF client.
To correct this you need to change:
return json_encode($customers);
to
return $response->withJson($customers);
Then all is well with the headers and works a treat with my WPF client.
Hey. Thanks for the tutorial. Wanted to ask you - why do u never put the closing '}' for json errors/notices?
For example: line 78 @ 38:36
Best Tutorials ever!
I normally dont comment on video`s, but awesome job Thank you for the video
Great video traversy as usual
Thankx brad. Happy Coding!
That was very helpfull, this was my first time doing an api with php and I loved it, thank you.
I know this is from 2016 but if you're reading this maybe you could try Insomnia, its an amazing program to try GET/REST http request.
Thanks this was very helpful.
Thanks nice video, i learned a lot with it !
Good overview! Is it normal that new \Slim\App is called 2 times in index.php and in customers.php ? (looks strange to me)
We are missing the sanitization of 'id' in SQL requests. We also don't check that the input parameters are well supplied in API requests.
that was really good, thanks!
great tutorial! this and together with the article i read on laravel api development has really made me understand how APIs work more, the only questions i have left now are: what instances are APIs useful? when/how will i know i should be building one for an application? if anyone could answer, i would greatly appreciate it.
Nice tutorial... thanks for the code sample
Thank you very much nice tutorial!!!
thank you for this. you're an angel! :)
Thanks for the Great Tutorial.May i ask, if you had to choose between Php Slim and Ruby Sinatra, which one would you choose?
That was awesome Sir!
Great tutorial great language, Thnx m8 :)
Great video man! thanks
thank you helped me a lot!
Thnx buddy. Great job. :D
Nice tutorial to understand the basics of the slim framework I really Wonder if you could implement a MVC structure in a little project for another tutorial, keep it up! and hope you do a tutorial of what I told you.
Very good video, thank you.
Hi Brad, where is the video on building a front-end for this tutorial? I would love to learn how you build it.
Nice tutorial. The reason the update did not work initially is that you have to build the update command based on the parameters that were passed in the json object.
Awesome tutorial!
@Traversy Media your vids are awesome, thanks a lot, is there a front-end video
Thanks for the tutorial!!
edit:
Uh oh, do I spot the Adobe registration "fix" in your hosts file?
Great video, thanks !
You are Amazing , thank you
Very informative.
Great work... Thanks
Instead of binding each parameter, you can also do the following:
$stmt = $db->prepare($sql);
$stmt->execute([
":firstname" => $firstname,
":lastname" => $lastname,
"birthdate" => $birthdate,
...
]);
thank you
Or you can include them right in the statement. But the bind one is better if you want to controll each of them one by one.
or just use the question mark placeholder for the properties and put the variables into the array in the right order
great tutorial. thanks a lot
IT IS NICE TUTORIAL. THANKS...
great! thank's for sharing!
11:35 how to add virtual host
above thing is not working on my machine
XAMPP giving error. This may be due to a blocked port, missing dependencies,
Thanks this is very helpfull
awesome man, thanks
How do you learn all this stuff. I'm struggling with just Javascript and Php alone :(
Lots of reading and watching tutorials. I felt the same way at one point. Keep at it and it will just start to click.
Adam Tak I been learning off youtube & lynda.com . also go to coding meetups and try to work on small projects with other people, you get so many motivation from people, and ideas just come natural.
The best method that worked for me was asking Web Design companies near me if they accepted interns at the moment, thankfully a few called back and from there I been learning off the more experienced developers.
goodluck brother & happy coding!
Hey man, just dont give up, we all went through the same problems, but at some point it will start to get easier and easier. In my opinion, the most important things are consistency and your will to advance in this field.
Okay thanks guys.
If you are watching this video than you're going in the right path!
Thank You so Much You saved me :)
Loved it
Well done!
Congratulations on the videos!
Do you have tutorial to protect the routes? for example: I only allow access to routes if I am logged in
amazing tutorial thanks
I please request another video on consuming this API from Angular. I think you need the Angular app to be on the same domain in order to use the API, but there are ways around that. So it would be really helpful to know how to structure the Angular app to work with these API files. Maybe cover the situation where the API is on the same server as the front end app, and another situation where it's not. :)
Also, for Anguar, all other RUclips videos assume the backend is Node, but many like me just use a regular non-Node supported hosting company that supports PHP.
I don't know what you prefer but what I do is run two virtual machines with different ip addresses and put my frontend on one and my backend on the other. More specifically I use VirtualBox as a standard installation and then I use vagrant. You can use Scotchbox to get an instant fully configured virtual machine to simulate hosting on both boxes. I change the IP addresses in the vagrantFile before I run vagrant up to create the machines. Then I use Angular CLI to build my application using the standard commands. Then change the path in the Angular.JSON file for the build so that when you run $ ng build it builds to the public dir of the frontend machine. Then you can call your backend API on the backend machine where your database lives using your frontend from the frontend machine. There's almost zero configuration involved. Not hard to get setup with this and you can deploy as many machines as you please. It's very quick if you work on multiple projects etc.
Hello, great video! Can you please make a video or give instruction about how to create a key for this API?
thx good job! helped alot
Thanks man,
I was looking for something similar to this. But not using PDO.
But it will do the good. And in this process i get to know about PDO
Once again thank you.
And have you uploaded the second part which you talked in last about the front end part ?
Hey Brad, Can you please show me how to authenticate this API with JSON tokens.
I try to make a easy way to protected unauthorized access my api by creating a new class(tools) add below in /src/config/tools.php
Awesome tutorial!
...Just got stuck in the PDO fetching part at 32:02.
It's returning me an array, and I can't use json_encode with that result.
Could someone help me?
Thanks in advance!
I have same issue.
Try this:
return $response->withStatus(200)->withJson($customers);
Thank you so much!
Simpy the best tutorial! WoW
nice tut. thank you
Excellent. I'm going to try and using mysqli. Could you elaborate how you can limit the api via a key of some sort?