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/
  • НаукаНаука

Комментарии • 424

  • @user-lq7hp8ps2m
    @user-lq7hp8ps2m Месяц назад

    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!

  • @marcjhonlawingco4959
    @marcjhonlawingco4959 6 лет назад +3

    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.

  • @McMurchie
    @McMurchie 7 лет назад +1

    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!

  • @TheDigiCraft
    @TheDigiCraft 7 лет назад +14

    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!

  • @user-ym2nm3dg2t
    @user-ym2nm3dg2t 7 лет назад

    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!

  • @AndroidHacksAH
    @AndroidHacksAH 6 лет назад +1

    Cheers man. I learned from your nodejs tutorials and now PHP 🙏

  • @DashCamJournalsPH
    @DashCamJournalsPH 6 лет назад

    Nice tutorial, exactly what I needed for weeks. Thumbs up!

  • @kyozoku1
    @kyozoku1 6 лет назад

    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!!

  • @renato_andrade
    @renato_andrade 6 лет назад

    Thank you so much for spend so much time doing this video! Was really helpful for me!

  • @AS-zw4lk
    @AS-zw4lk 6 лет назад

    Thanks! Nicely done. Really useful.I like the way you go from the very beginning.

  • @briansilvers6890
    @briansilvers6890 7 лет назад

    This was a big help in putting a few concepts into perspective. Thank you.

  • @luisgabriel84
    @luisgabriel84 6 лет назад

    Great Tutorial Brad, simple and useful just what i needed.

  • @bullcitty4690
    @bullcitty4690 6 лет назад

    Awesome instructor, your videos are the best!!!! Thanks!

  • @iancarr3923
    @iancarr3923 6 лет назад

    Another great video. Fits in well with a current project.

  • @thesecretcodeoflaughs9645
    @thesecretcodeoflaughs9645 6 лет назад

    Thank you, this was exactly what I need for my project...

  • @shitanshuchouksey977
    @shitanshuchouksey977 6 лет назад

    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 :)

  • @muhammadwaris9834
    @muhammadwaris9834 7 лет назад

    One of the best video on REST FULL API

  • @strukki2
    @strukki2 5 лет назад

    Even my grand ma would understand your explanations! Thanks a lot. You are great!

  • @scratchercatcher6760
    @scratchercatcher6760 6 лет назад

    Thank you very much! You saved tons of time for me. Great tutorial!

  • @pepecalixto2790
    @pepecalixto2790 7 лет назад

    Excellent tutorial! :) Congrats and thank you for sharing your knowledge!

  • @elan311X
    @elan311X 7 лет назад

    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.

  • @JeetDholakia
    @JeetDholakia 7 лет назад

    Great video! was looking for such video since very long and ur video is to the point and easy to understand.

  • @douglasemsantos
    @douglasemsantos 7 лет назад

    Excellent tutorial! Thank you! It helped me a lot!

  • @AntonioSantosYT
    @AntonioSantosYT 7 лет назад

    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!

  • @marianamedeiros9361
    @marianamedeiros9361 7 лет назад

    Thank you for sharing this with us! Amazing tutorial!

  • @bogdanmarian3786
    @bogdanmarian3786 4 года назад

    Awesome tutorial ! Thank you Brad !

  • @mudkipdan
    @mudkipdan 7 лет назад

    Thanks for this, this was my first time doing a CRUD based API in slim. :)

  • @logion7
    @logion7 7 лет назад +2

    Excellent work, man!

  • @johnybravo2590
    @johnybravo2590 7 лет назад

    That is a very useful and very well prepared tutorial! Thanks! :)

  • @JitenderKumar-gz5bm
    @JitenderKumar-gz5bm 5 лет назад

    Nicely Explained Tutorial!! Thanks for the efforts!! Keep up the good work!! Cheers!!

  • @BadalKumar-jm7tg
    @BadalKumar-jm7tg 7 лет назад +1

    Thanks a ton! you saved my day! it really helps me to write back-end code as i am Android Dev. thanks again!

  • @ConquerJS
    @ConquerJS 7 лет назад +3

    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!

  • @abc2phd
    @abc2phd 6 лет назад

    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.

  • @nickcourage7059
    @nickcourage7059 3 года назад

    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.

  • @robertojf2012
    @robertojf2012 6 лет назад

    Excellent explanation, thank you very much! :D

  • @VijaySharma-fw2uc
    @VijaySharma-fw2uc 7 лет назад

    Very clear and concise ,Thank you

  • @kamaboko1
    @kamaboko1 6 лет назад

    Very useful tutorial. Thanks for posting. Looking forward to your Vue,js frontend tut.

  • @SimPwear84
    @SimPwear84 7 лет назад

    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!

    • @dislikecounter6392
      @dislikecounter6392 2 года назад +1

      It took me like 4 attempts to actually use this to make a persistent server in UE4

    • @SimPwear84
      @SimPwear84 2 года назад

      @@dislikecounter6392 that is why I am never giving up on learning again. Imagine if you gave up on the first attempt?

    • @dislikecounter6392
      @dislikecounter6392 2 года назад +1

      ​@@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.

    • @SimPwear84
      @SimPwear84 2 года назад

      @@dislikecounter6392 Breaks are always good. Highly recommended

  • @johnnysalami152
    @johnnysalami152 5 лет назад

    good video! i just set it up and everything worked as you said in the video! thanks

  • @MrEasternedge
    @MrEasternedge 6 лет назад

    Thanks always Traversy Media...

  • @rotrose7531
    @rotrose7531 6 лет назад

    It is a genuinely exellent video. Thank you

  • @bi0s1337
    @bi0s1337 6 лет назад

    Best Video ever!! Thank you so much! I try now to create a ReactJS Frontend ;)

  • @ericsonfuntanar4026
    @ericsonfuntanar4026 5 лет назад

    Awesome bro. Thankyou. I might use this with react.

  • @valijonrahimov6765
    @valijonrahimov6765 7 лет назад +15

    Great tutorial. Let's do the VueJS frontend to this api. I will give a try) thanks.

    • @TraversyMedia
      @TraversyMedia  7 лет назад +10

      Good Call! Ill see what I can do

    • @eduardojonnerstig5554
      @eduardojonnerstig5554 7 лет назад

      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

  • @4RV1DDesigns
    @4RV1DDesigns 6 лет назад

    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.

  • @robinstott8581
    @robinstott8581 7 лет назад +2

    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.

  • @wvvwwwvvw
    @wvvwwwvvw 7 лет назад +1

    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

  • @sebastianhiguita933
    @sebastianhiguita933 7 лет назад +7

    Best Tutorials ever!

  • @dancole49
    @dancole49 6 лет назад

    I normally dont comment on video`s, but awesome job Thank you for the video

  • @MG-bm5oj
    @MG-bm5oj 6 лет назад

    Great video traversy as usual

  • @NadeemGorsi
    @NadeemGorsi 5 лет назад

    Thankx brad. Happy Coding!

  • @dustnoiseplays
    @dustnoiseplays 4 года назад

    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.

  • @SpankyDePanky
    @SpankyDePanky 6 лет назад

    Thanks this was very helpful.

  • @evertonbuzzi5884
    @evertonbuzzi5884 5 лет назад

    Thanks nice video, i learned a lot with it !

  • @optimiserlenergie1094
    @optimiserlenergie1094 4 года назад +2

    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.

  • @keremoflu
    @keremoflu 6 лет назад

    that was really good, thanks!

  • @alexyap4686
    @alexyap4686 6 лет назад

    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.

  • @vigneshlakshmanan8575
    @vigneshlakshmanan8575 6 лет назад

    Nice tutorial... thanks for the code sample

  • @kirru4
    @kirru4 7 лет назад

    Thank you very much nice tutorial!!!

  • @maki9876
    @maki9876 6 лет назад

    thank you for this. you're an angel! :)

  • @PeterParker-sy9bp
    @PeterParker-sy9bp 7 лет назад

    Thanks for the Great Tutorial.May i ask, if you had to choose between Php Slim and Ruby Sinatra, which one would you choose?

  • @mathon2462
    @mathon2462 7 лет назад

    That was awesome Sir!

  • @yilmaz8072
    @yilmaz8072 6 лет назад

    Great tutorial great language, Thnx m8 :)

  • @jcsto
    @jcsto 7 лет назад

    Great video man! thanks

  • @shlomitofahi668
    @shlomitofahi668 3 года назад

    thank you helped me a lot!

  • @tareqislam8644
    @tareqislam8644 6 лет назад

    Thnx buddy. Great job. :D

  • @ernestorojas1119
    @ernestorojas1119 6 лет назад

    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.

  • @widden_
    @widden_ 6 лет назад

    Very good video, thank you.

  • @pioleonardo
    @pioleonardo 5 лет назад +1

    Hi Brad, where is the video on building a front-end for this tutorial? I would love to learn how you build it.

  • @jacquestremblay4044
    @jacquestremblay4044 4 года назад

    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.

  • @eddiegere
    @eddiegere 7 лет назад

    Awesome tutorial!

  • @mmathenge5969
    @mmathenge5969 7 лет назад

    @Traversy Media your vids are awesome, thanks a lot, is there a front-end video

  • @CrippleX89
    @CrippleX89 7 лет назад

    Thanks for the tutorial!!
    edit:
    Uh oh, do I spot the Adobe registration "fix" in your hosts file?

  • @ciprianoteibao1342
    @ciprianoteibao1342 7 лет назад

    Great video, thanks !

  • @user-bk6qj7wo6n
    @user-bk6qj7wo6n 4 года назад

    You are Amazing , thank you

  • @charbelsarkis3567
    @charbelsarkis3567 6 лет назад

    Very informative.

  • @teresabove7191
    @teresabove7191 5 лет назад

    Great work... Thanks

  • @holonaut
    @holonaut 7 лет назад +10

    Instead of binding each parameter, you can also do the following:
    $stmt = $db->prepare($sql);
    $stmt->execute([
    ":firstname" => $firstname,
    ":lastname" => $lastname,
    "birthdate" => $birthdate,
    ...
    ]);

    • @johnhans4541
      @johnhans4541 6 лет назад

      thank you

    • @the_pheonix1
      @the_pheonix1 5 лет назад +1

      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.

    • @ColoniacsBrotherhood
      @ColoniacsBrotherhood 4 года назад

      or just use the question mark placeholder for the properties and put the variables into the array in the right order

  • @ArceAdriano
    @ArceAdriano 7 лет назад

    great tutorial. thanks a lot

  • @RahulPatel-pe9id
    @RahulPatel-pe9id 4 года назад

    IT IS NICE TUTORIAL. THANKS...

  • @guianzollin
    @guianzollin 7 лет назад

    great! thank's for sharing!

  • @jonsnow9758
    @jonsnow9758 5 лет назад +1

    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,

  • @fahmiirfan6923
    @fahmiirfan6923 6 лет назад

    Thanks this is very helpfull

  • @7huannp
    @7huannp 6 лет назад

    awesome man, thanks

  • @adamtak3128
    @adamtak3128 7 лет назад +23

    How do you learn all this stuff. I'm struggling with just Javascript and Php alone :(

    • @TraversyMedia
      @TraversyMedia  7 лет назад +39

      Lots of reading and watching tutorials. I felt the same way at one point. Keep at it and it will just start to click.

    • @kairoswave
      @kairoswave 7 лет назад +4

      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!

    • @webpocetnik7862
      @webpocetnik7862 7 лет назад +12

      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.

    • @adamtak3128
      @adamtak3128 7 лет назад

      Okay thanks guys.

    • @AntonioSantosYT
      @AntonioSantosYT 7 лет назад +6

      If you are watching this video than you're going in the right path!

  • @solarguidetoday
    @solarguidetoday 6 лет назад

    Thank You so Much You saved me :)

  • @zixxtrth9000
    @zixxtrth9000 7 лет назад +1

    Loved it

  •  7 лет назад

    Well done!

  • @limaand2009
    @limaand2009 4 года назад

    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

  • @itaichiriseri2739
    @itaichiriseri2739 6 лет назад

    amazing tutorial thanks

  • @JBuchmann
    @JBuchmann 6 лет назад

    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.

    • @michaeloakenfall5743
      @michaeloakenfall5743 5 лет назад

      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.

  • @panagiotis9688
    @panagiotis9688 6 лет назад +1

    Hello, great video! Can you please make a video or give instruction about how to create a key for this API?

  • @amird1889
    @amird1889 5 лет назад

    thx good job! helped alot

  • @mdsbzalam
    @mdsbzalam 7 лет назад

    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 ?

  • @lifecyclevlog
    @lifecyclevlog 7 лет назад +5

    Hey Brad, Can you please show me how to authenticate this API with JSON tokens.

    • @satitpherm8764
      @satitpherm8764 5 лет назад

      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

  • @rogeriorodrigues4210
    @rogeriorodrigues4210 6 лет назад +5

    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!

    • @TheNanoWeb
      @TheNanoWeb 6 лет назад

      I have same issue.

    • @DailyVisualMusic
      @DailyVisualMusic 5 лет назад +2

      Try this:
      return $response->withStatus(200)->withJson($customers);

  • @kowdtv6176
    @kowdtv6176 6 лет назад

    Thank you so much!

  • @avishkarabhishek896
    @avishkarabhishek896 7 лет назад

    Simpy the best tutorial! WoW

  • @onurcelik34
    @onurcelik34 7 лет назад

    nice tut. thank you

  • @MiguelRamirez-ld7sy
    @MiguelRamirez-ld7sy Год назад

    Excellent. I'm going to try and using mysqli. Could you elaborate how you can limit the api via a key of some sort?