Answer the question
In order to leave comments, you need to log in
What is the best way to implement a HTTP GET request to the REST API in PHP?
I've only been in PHP for a few days.
I need to send a GET request to a third party resource (API) over HTTPS.
I "googled" the following options:
1) cURL;
2) Guzzle;
3) HttpRequest;
What would you recommend to use?
Answer the question
In order to leave comments, you need to log in
Definitely Guzzle.
This is a high-level library that will make low-level requests via CURL itself.
Describe the task in more detail: how often it needs to be done, what restrictions, what to do next.
Maybe you don't need php?
Enough
var img = document.createElement('img');
img.src = 'example.com/path/to/api/to/make/a/simple/signal;
well, and advice ...
dude, you need to raise a whole server, and there, through the old module that needs to be added to the kernel, it will access another api resource through the api of the module itself!
everything is simple! good luck ;)
Opinions were divided... I
will explain more in detail: the user enters the name in the form; this name is passed to the server by AJAX and matched in the database by ID. The server then sends a GET request over HTTP with this ID and other fixed parameters. Interaction with a third-party resource is carried out only with the help of GET requests.
This example from the service https://www.bytehand.com there is documentation on the API example, you can easily implement it!
$phone = '79123456789';
$request_params = [
'id' => '355555',
'key' => '2E31561235B43932',
'to' => "$phone",
'from' => 'sms-info',
'text' => 'Ваш заказ обработан пожалуйста проверьте вашу почту'
];
$url = "http://api.bytehand.com/v1/send?" .http_build_query($request_params);
//Разкоментируйте строчку ниже если хотите отправить запрос со своего OpenServer или просто введите в
//строку браузера после получения var_damp еще добавьте https если у вашего хостинга есть
//SSL сертификат иначе не отправится запрос УДАЧИ!
//file_get_contents($url) ;
var_dump($url);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question