Тёмный

How to use a REST API from PHP using cURL | Full PHP cURL API tutorial 

Dave Hollingworth
Подписаться 25 тыс.
Просмотров 37 тыс.
50% 1

Learn how to use a REST API from PHP using cURL.
Support my channel: ☕ ko-fi.com/davehollingworth
Full PHP APIs course: ➤ davehollingworth.net/phpapisy
You'll learn the following:
- The basics of making API requests in PHP
- Encode and decode JSON data
- Send request headers
- Use different request methods (GET, POST, PATCH, DELETE etc.)
- Respond to different HTTP status codes
Code shown in the video:
github.com/daveh/php-curl-cru...
Resources shown in the video:
www.php.net/manual/en/book.cu...
docs.github.com/en/rest
picocss.com/
00:00 Introduction
00:21 PHP cURL basics
01:42 Add request headers
04:14 Get a string response
05:11 Decode JSON
09:26 Endpoints with IDs
12:35 Setting endpoints
14:33 Multiple cURL options
18:38 POST requests
20:59 HTTP status code
26:57 PATCH requests
28:26 DELETE requests
30:37 Outro
#PHP #API #cURL

Наука

Опубликовано:

 

25 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 57   
@ilyamur885
@ilyamur885 2 года назад
Your tutorials are best, Dave! Keep up the good work!
@tonyhomfray
@tonyhomfray 2 года назад
This gives such clear descriptions and full explanations of what you are doing and why at every step. Wonderful content. Thank you!
@novakjetil
@novakjetil 2 года назад
great tutorial, Dave! Was just googling for this earlier today, and you posted this tonight! Cheers
@rshelfo1
@rshelfo1 2 года назад
been struggling for days to just create a simple cURL POST api client, thankyou so much this has been the MOST informative breakdown of doing just that. and unlike most other online resources, you dont write the code line by line, you build the app as it should be built. Amazing work
@chadmasters3935
@chadmasters3935 2 года назад
Enjoyed your video. I'm trying to get back into PHP after a very long hiatus (PHP 4) . Thanks for your videos for seeing what's new under the sun.
@BoneyardHauntedHouse
@BoneyardHauntedHouse 2 года назад
Clear, concise, spot on!,,,, thank you very much for passing it on..
@bugsbunny9965
@bugsbunny9965 2 года назад
Easy to understand, Love it, Thank you Dave. 👍
@lexiriam
@lexiriam 3 месяца назад
Your video tutorial is one of the best out there. Thank you for walking through and explaining the process in a slow, understandable method. I'm a subscriber!
@SLCODEGEN
@SLCODEGEN 2 года назад
Thank you!! such a neat & clean tutorial.
@athithyaparamesh8251
@athithyaparamesh8251 2 года назад
Just what I was looking for! Thanks a lot.
@piyushakoliya72
@piyushakoliya72 5 месяцев назад
Amazing tutorial Dave.. very well explained..
@johnnyvandenelzen2250
@johnnyvandenelzen2250 Год назад
You sir, display such a clean and proper way of teaching. It is such a relief to find videos with these topics on RU-vid that are spoken in proper English. Although I respect every individual that commits his/her time to produce free educational content, I am quite disappointed by the utter polution that exists on RU-vid nowadays. I am speaking of all the educational videos that seem to be produced with the proper use of the English language at first (e.g. English title, English thumbnail, English useraccount, English description) but once started only lead to disappointment because the speaker is someone who barely speaks understandable English. I say this with a certain level of understanding yet quite the amount of resent because it makes my personal user experience on RU-vid worse than it was before. Long story short, Dave Hollingworth, you are a godsend and I thank you for your videos!
@dave-hollingworth
@dave-hollingworth Год назад
Thank you so much for your kind words Johnny!
@mullertm4778
@mullertm4778 2 года назад
thanks for this tutorial it's super useful keep it up
@michellemartinez-vc1mj
@michellemartinez-vc1mj Год назад
Thank you for this explanation. This helped me so much.
@craigc5879
@craigc5879 2 года назад
Another excellent video
@sorasoralee2127
@sorasoralee2127 2 года назад
you help me a lot! thank you !
@PrivateNaelyan
@PrivateNaelyan 10 месяцев назад
Nicely explained!
@Iconic-scenes
@Iconic-scenes Год назад
Very good video, keep on the good work :)
@themonster4759
@themonster4759 Год назад
thanks for your effort this is helpful
@user-qs8be1dp5i
@user-qs8be1dp5i 9 месяцев назад
Hello Sir, Thank you so much for the tutorials such a clear and steady voice to follow and learn things. I ever seen such a tutorial before. very useful👏👏👏👍👍👍
@divineembassychildrenschoi6317
@divineembassychildrenschoi6317 11 месяцев назад
Wow this was really great iam happy i found you , you just gained a new w in the chat
@JuanBotes
@JuanBotes 2 года назад
Thanks for the great content \o/
@b.sivakumar4328
@b.sivakumar4328 Год назад
Thank you
@SkLzaGaming
@SkLzaGaming 2 года назад
dave bro, u are just awesome. u will be great in future. remember.
@tazefaze
@tazefaze 2 года назад
Thank you.
@taelabaho
@taelabaho 2 года назад
this is gold
@mazs3364
@mazs3364 Год назад
Hi Dave, great video, thank you. was trying to show other details for the repository like the files. any hints would be appreciated. thanks
@dave-hollingworth
@dave-hollingworth Год назад
You can adapt the code that shows a 404 to allow other URL segments, or use a third-party router if you have a lot of resource endpoints
@deesolvero5548
@deesolvero5548 2 года назад
Hi Dave! I love your tutorials and I learned a lot from it. However, I am struggling in show.php because of undefined array in dl part.
@dave-hollingworth
@dave-hollingworth 2 года назад
Try comparing your code to the source code linked to in the description, see if there's a typo in your code maybe
@brendanhedges7591
@brendanhedges7591 2 года назад
Hi, A nice video, thank you. It helped a lot. How about making a video on retreaving data from an API with PHP/Curl and saving that data to a database, then retreaving the data and displaying it in HTML (for example on a users profile page). I'm thinking more of dynamic applications like Joomla.
@lilliannjihia8557
@lilliannjihia8557 2 года назад
Hey! Have you been able to work this out? I'm currently working on a problem that would require the same. But from what i can tell, if you isolate the variable names, you can run insert statements into your db in a straightforward manner.
@gunnarnopens2244
@gunnarnopens2244 2 года назад
Great tutorial … tried it to get data from Notion but struggling to display data from their array like you did with repository … can you make a tutorial for that?
@dave-hollingworth
@dave-hollingworth 2 года назад
Not familiar with Notion but will take a look and add it to my list, thank you!
@philadams9254
@philadams9254 Год назад
This is great. I've implemented this and your tutorial on creating a restful API in PHP, but I can't get cURL to connect to my API. For some reason, whether it's localhost or a proper server, because both are on the same server, it just won't connect. I think it could be some sort of firewall issue or maybe a PHP setting I don't know about. Any help on that would be appreciated.
@dave-hollingworth
@dave-hollingworth Год назад
What happens when you try and connect, do you get any error messages at all?
@philadams9254
@philadams9254 Год назад
@@dave-hollingworth No, nothing, which is the most frustrating part! The cURL response is just empty with a 200 code and the script at the other end somehow gets called but also receives an empty request with no data. Bizarre!
@dave-hollingworth
@dave-hollingworth Год назад
@@philadams9254 Try running the code from the video, there's a link in the description, see if that makes a difference - if so, try comparing yours to that code, see if you can spot a discrepancy that might be causing the error
@matteonicoli
@matteonicoli 11 месяцев назад
I feel so stupid. I'm getting a blank screen. On my wamp (windows 11 display_errors=On) as well as on my live server. I am at a complete loss here. PHP directly copied, with new github access token.
@matteonicoli
@matteonicoli 11 месяцев назад
I solved it. I went to work to hasty (which of course is never good combined with late night coding). I dowloaded your code from github and used file init_curl. Did paste the access token header but forgot to paste the url. In my production curl project I got a blank screen as well, while everything worked fine in Postman. Until I added this line CURLOPT_SSL_VERIFYPEER => false, I received data (so relieved). Felt helpless for 2 days. In any case, Dave Hollingworth and many thanks. Will be watching a lot more excellent tutorials from you in the future.
@lilliannjihia8557
@lilliannjihia8557 2 года назад
Question: at 6:47 in running the foreach function, how do I begin troubleshooting if my code doesn't isolate the specific fields I'm interested in as yours did?
@dave-hollingworth
@dave-hollingworth 2 года назад
Try printing out the contents of the various variables you're using before, during and after the loop using var_dump for example
@lilliannjihia8557
@lilliannjihia8557 2 года назад
@@dave-hollingworth Lemme try that out. also some of the variables I'm looking for are nested within the primary array... How do I go about that?
@dave-hollingworth
@dave-hollingworth 2 года назад
var_dump will print out the full contents of a multidimensional array, and you can call it from within a loop
@lilliannjihia8557
@lilliannjihia8557 Год назад
@@dave-hollingworth Hey Dave, I'm still having trouble isolating specific fields in my array response (my array response is very nested). For some reason it's not responding like in the tutorial with I identify the array indexes... I'm not sure why or whether it could be because of the structure of my array.
@dave-hollingworth
@dave-hollingworth Год назад
@@lilliannjihia8557 Try debugging it by using print_r for various different levels of the array
@yousseflahmadi7665
@yousseflahmadi7665 2 года назад
Hi , i have a little question , when i try to echo some entities Like in the vedio for fullname name and discerption i get the error Cannot access offset of type string on string anyone have any ideas? Thank you in advance .
@dave-hollingworth
@dave-hollingworth 2 года назад
It means you're trying to use a string as an array: stackoverflow.com/a/20271518
@gennadyga2257
@gennadyga2257 2 года назад
What is IDE? Very simple and powerful)
@dave-hollingworth
@dave-hollingworth 2 года назад
I use Atom - atom.io/
@battowsai
@battowsai Год назад
@@dave-hollingworth as ATOM is getting retired this December, did you decide on a new IDE? im just starting to learn and would be interested on which alternative i might look for.
@dave-hollingworth
@dave-hollingworth Год назад
@@battowsai I recommend Visual Studio Code, it's free and cross platform. (I'm still going to use Atom for my videos for the foreseeable future as it's very minimalist and works well for video tutorials, but if you're coding yourself, I would use VSCode)
@battowsai
@battowsai Год назад
@@dave-hollingworth thank You for the answer. I guess i will try atom for the first project. This Tutorial will help me alot. The only problem i habe is that i Need to call three different rest api and compare the items.
@toano8855
@toano8855 2 года назад
hi bro, I have a question. How to curl without reload page?
@dave-hollingworth
@dave-hollingworth 2 года назад
cURL is called on the server, so you could call a page that used cURL using Ajax, or call the API directly from JavaScript
@michaelrorong
@michaelrorong Год назад
Bang kok lu mirip doctor strange
Далее
using curl better - with curl creator Daniel Stenberg
55:46
2DROTS vs RISENHAHA! КУБОК ФИФЕРОВ 2 ТУР
11:31
PHP + curl - A Simple example of how to use cURL
13:43
How to Build a REST API With Laravel: PHP Full Course
1:49:26
How to use PHP cURL to Handle JSON API Requests
10:57
Просмотров 117 тыс.
PHP REST API From Scratch [1] - Database & Read
32:18
Просмотров 510 тыс.