How to call APIs from PHP: file_get_contents, cURL, Guzzle and SDKs

Поділитися
Вставка
  • Опубліковано 18 вер 2024

КОМЕНТАРІ • 72

  • @jediampm
    @jediampm 3 роки тому +7

    Hi, thanks for the video.
    Great explanation.
    Two things to point out:
    - to use curl with php, for dev (in your local PC) you need to install curl and respective php extension.
    - Guzzle behind the scenes will use curl if it install, if not you should had allow_url_fopen option enable.

  • @blessed-favored
    @blessed-favored 2 роки тому +2

    Thanks man. One of the best if not the best content on UA-cam about APIs.

  • @MrWilliamwright
    @MrWilliamwright 3 роки тому +4

    Your courses are so good and full of useful info, thanks a lot.

  • @shubhamtiwary2524
    @shubhamtiwary2524 3 роки тому +6

    Your courses are great. One request though, could you do a video on how to make our own apis in php.

  • @Shiv-vb1re
    @Shiv-vb1re 3 роки тому

    Thanks sir i bought the php course and completed it
    I learnt a lot

  • @jeanlegrandbokassa6688
    @jeanlegrandbokassa6688 3 роки тому +2

    Thank you ! This video just come in the right time for me !!!

  • @vivamedia5958
    @vivamedia5958 3 роки тому +2

    Awesome. Thanks
    If possible please more info about advantages and disadvantages of each one.

    • @dave-hollingworth
      @dave-hollingworth  3 роки тому +2

      I did cover these in the video - using file_get_contents is part of base PHP, so you don't have to install anything, but it does require that setting to be enabled in php.ini. Also, to send headers you need to separate each one with newline characters that can be prone to errors. cURL is a PHP extension, so you have to make sure it's installed, but it's easier to use than file_get_contents. Guzzle is simpler to use as it's object oriented, but it does use cURL under the hood by default, so you have to make sure cURL is installed.

    • @vivamedia5958
      @vivamedia5958 3 роки тому +2

      @@dave-hollingworth I'm sincerely thankful.

  • @baebonana9826
    @baebonana9826 Місяць тому

    Superb! I'll replicate the steps now. Well explained.

  • @charlestazerussell6725
    @charlestazerussell6725 Місяць тому

    Excelente comparativa. Muchas gracias

  • @JahidHasan-zn6xj
    @JahidHasan-zn6xj 2 роки тому +1

    I really love your videos❤️
    The way you explain and everything in details love it.👌

  • @blessed-favored
    @blessed-favored 2 роки тому

    Kindly consider doing a video talking more about SDKs. For example how to write them.

  • @mahmoudusman5330
    @mahmoudusman5330 3 роки тому

    Thank Mr Dave.
    Just the video I have been searching for.
    It's just as if you made this video because of me.
    Thank you

  • @renemayett5161
    @renemayett5161 Рік тому

    Thanks a lot sir! Best regards from Mexico 👍

  • @Gricenich
    @Gricenich 2 роки тому

    Thank you so much Dave, it's a great explanation, you saved my time!

  • @collenzaligway4458
    @collenzaligway4458 2 роки тому

    Your content are great, hope you keep posting more cause its informative specially the OOP videos. Cheers mate

  • @godofnothing520
    @godofnothing520 3 роки тому +1

    Can you create a Laravel course on udemy, please? Your Codeigniter course on udemy is perfect, and your voice is kinda soothing. Also, your code is well structured.

    • @dave-hollingworth
      @dave-hollingworth  3 роки тому

      Thank you for your kind words! I'll let you know if I do! :-)

  • @isaacrafaelnunezservian708
    @isaacrafaelnunezservian708 2 роки тому

    Thanks bro! Great translation!

  • @KudoMarkos
    @KudoMarkos 2 роки тому +1

    Thank you a lot

  • @rafaelfigueiredofurini6327
    @rafaelfigueiredofurini6327 2 роки тому +1

    First of all, thanks, your videos are great....my question: How to debug my requests? In the video the are options to see http responses only(header and body)...

    • @dave-hollingworth
      @dave-hollingworth  2 роки тому

      I'm glad you like the videos! To properly debug requests, I recommend using an API client like Postman (www.postman.com/) or HTTPie (httpie.io/)

  • @gennadyga2257
    @gennadyga2257 2 роки тому +1

    Very thanks!!!

  • @sampahemmanuel2643
    @sampahemmanuel2643 2 роки тому +1

    Awesome video. Please can the Guzzle be used for streaming.

  • @erichepperlewp
    @erichepperlewp 2 роки тому

    00:05:00 - #file_get_contents(); ADVANTAGES: Part of PHP core; doesn't require extensions or external dependencies. DISADVANTAGES: Returns false for unsuccessful status request with no debugging data; Sending multiple request headers requires concatenation; Retrieving URLs requires allow_url_fopen() to be enabled which is commonly NOT enabled on "cheap shared hosting"

  • @mehrdadriyahi2746
    @mehrdadriyahi2746 2 роки тому

    Thanks for your wonderful video.

  • @marting169
    @marting169 2 роки тому +1

    GRACIAS!!!! Excelent!!

  • @sivaprasadsiva1770
    @sivaprasadsiva1770 6 місяців тому

    which one is best for Android Application

  • @dawid_dahl
    @dawid_dahl 2 роки тому

    Perfect, thank you so much!

  • @duyphi5035
    @duyphi5035 Рік тому

    Thank you for your very detailed instructions. I have a question. I want to build a search form when I enter keywords into that form and press the search button it will call to another website and then I also want to use code to perform operations like searching for something in the form of that website instead of having to go to that website to enter it manually, then also use the code to automatically click the search button (submit button) in that website (if any) and then get that search results return to my localhost website. How can I do this?

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      Not sure you can do that with PHP - there's a thread here that discusses it: stackoverflow.com/questions/55369863/how-can-i-use-php-to-prepopulate-a-form-on-or-send-data-to-a-3rd-party-website

  • @User97356
    @User97356 Рік тому

    شكراً thank you

  • @RodrigoSotoCastro
    @RodrigoSotoCastro 2 роки тому

    Nice video bro, thanks!

  • @RagHelen
    @RagHelen 3 роки тому +1

    Dave, do you have any recommendations for books about the underlying logic and physics of PHP?

    • @dave-hollingworth
      @dave-hollingworth  3 роки тому +1

      Not sure about books, but this article is very interesting: thephp.website/en/issue/how-does-php-engine-actually-work/

  • @mathieustamm7395
    @mathieustamm7395 Рік тому

    Hello, from what I understand, your function, with the file_get_content, encode.
    Personally, I would like to do the opposite, I have an api but special characters such as # or - and " are not displayed, I would even say that they are not taken into account. My question is, can I use your code to do the opposite of what you do?

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      I'm not sure what you mean - the code in the video will call an API and display the response. If you're not seeing some characters, it could be a character encoding issue

  • @ademineshat
    @ademineshat 3 роки тому

    Thanks for sharing, but it's very disturbing having 6 advertisement interruptions with 2 ads in a row 🙄

  • @nemac23
    @nemac23 2 роки тому

    Awesome

  • @kevyyar
    @kevyyar Рік тому

    how do you caches the api get responses?

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      There are many ways to cache in PHP - some libraries here: www.google.co.uk/search?q=php+cache+library

  • @andresalvarez9394
    @andresalvarez9394 2 роки тому

    Hi!
    First of all very usefull video
    Second I have a problem usign cURL, when I try to update the value of "title" I get this response
    string(103) "{ "userId": 1, "id": 1, "title": "quidem molestiae enim", "{\"title\":\"Updated title\"}": "" }"
    How can I solve this problem?
    Thanks!

    • @dave-hollingworth
      @dave-hollingworth  2 роки тому

      It looks like you're escaping the updated title value - what code are you using to generate that JSON?

  • @chromeuser7363
    @chromeuser7363 Рік тому

    I am trying to read file from api but neither file_get_contents nor curl are working on hosting website even if allow_url_fopen is On as shown in phpinfo.

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      Could be a network restriction - if the same code works locally, I would check with your hosting provider why it doesn't work there

    • @chromeuser7363
      @chromeuser7363 Рік тому

      @@dave-hollingworth on file_get_contents I'm getting failed to open stream http 451 error.
      On cURL I am getting Moved 301 permanently error.

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      @@chromeuser7363 I've not seen 451 before - that suggests it's being blocked though: en.wikipedia.org/wiki/HTTP_451

  • @devijv1441
    @devijv1441 Рік тому

    Which a fastest library?

    • @dave-hollingworth
      @dave-hollingworth  Рік тому

      I haven't noticed a performance difference, but calling built-in functions will in theory be faster than using a library like Guzzle

  • @rosed4878
    @rosed4878 3 місяці тому

    Im not sure why but i copied your code down from the 1:46 mark but all i got was bool(false)

    • @dave-hollingworth
      @dave-hollingworth  3 місяці тому

      What is the line of code that's causing that error?

  • @2chainz576
    @2chainz576 10 днів тому

    what console is this?

    • @dave-hollingworth
      @dave-hollingworth  10 днів тому

      The default terminal app that comes with Xubuntu, but it's valid for the equivalent app for Windows, OSX etc.

  • @cansahin2724
    @cansahin2724 2 роки тому

    POSTing from a.php to b.php. I save it to the database and positive/negative results are returned. How can I print this result to my a.php file?

    • @dave-hollingworth
      @dave-hollingworth  2 роки тому

      If you want to go back to a.php, you'll need to redirect using a "Location" header. To display the data, a.php will have to read the database.

    • @cansahin2724
      @cansahin2724 2 роки тому

      @@dave-hollingworth Then this method doesn't work for me. Actually, what I want to do is: There is 1 order panel and orders will come to this panel from different sites. The people who make the sites should not see the database connection of the panel. After the POST process, the file on the server where the panel is located is also checked. And the result of this check needs to be transmitted from the panel to the form.

    • @cansahin2724
      @cansahin2724 2 роки тому

      How can I do it ? I couldn't find a properly working example. Very happy if you help.

    • @dave-hollingworth
      @dave-hollingworth  2 роки тому

      @@cansahin2724 If the value isn't sensitive data, then you could just include it in the query string when you redirect. Otherwise the calling site will need to request a URL that gives them this data somehow.

    • @cansahin2724
      @cansahin2724 2 роки тому

      @@dave-hollingworth I can't send the result back.

  • @oussamalabied513
    @oussamalabied513 2 роки тому

    in 9:34 i get :boolean false why

    • @dave-hollingworth
      @dave-hollingworth  2 роки тому

      This usually happens if the hostname is unreachable (i.e. the domain name is incorrect - in the video it's "jsonplaceholder.typicode.com"