A
A
Alexander2014-05-14 21:01:49
PHP
Alexander, 2014-05-14 21:01:49

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

6 answer(s)
N
Nazar Mokrinsky, 2014-05-14
@nazarpc

file_get_contents() doesn't work?

O
OnYourLips, 2014-05-14
@OnYourLips

Definitely Guzzle.
This is a high-level library that will make low-level requests via CURL itself.

V
Viktor Vsk, 2014-05-14
@viktorvsk

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;

Such is the uncomplicated and most resource-non-demanding implementation of a get request, as far as I know. (Maybe img should also be added to the DOM, but not sure.

S
Shurik, 2014-05-15
@aioon

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

A
Alexander, 2014-05-15
@pchelovek

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.

A
Andrew, 2018-10-07
@vulfru

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);
?>

Get a request of the form that will send to your service if php
api.bytehand.com/v1/send?id=355555&key=2E31561235B43932 '&to=79123456789&from=sms-info&text=%D0%92%D0%B0%D1%88+%D0 %B7%D0%B0%D0%BA%D0%B0%D0%B7+%D0%BE%D0%B1%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0 %D0%BD+%D0%BF%D0%BE%D0%B6%D0%B0%D0%BB%D1%83%D0%B9%D1%81%D1%82%D0%B0+%D0%BF%D1 %80%D0%BE%D0%B2%D0%B5%D1%80%D1%8C%D1%82%D0%B5+%D0%B2%D0%B0%D1%88%D1%83+%D0% BF%D0%BE%D1%87%D1%82%D1%83

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question