Jump to content

What do you use when work with remote API?


Zeka
 Share

Recommended Posts

I'm planning to start a project where remote API will be involved and thinking about tools to work with API. Of course, we have WireHttp class and actually, I think to go with it, but maybe there are more specialized alternatives that worth to consider?

Link to comment
Share on other sites

I tend to use wireHttp.

Here's a recent example:

https://github.com/adrianbj/CookieManagementBanner/blob/a8e66127bdcbd80e10ac797ad5cbb143644c7857/CookieManagementBanner.module#L38-L39

                $http = new WireHttp();
                $userLocation = $http->getJSON('https://extreme-ip-lookup.com/json/'.$this->get_user_ip_addr());

 

image.png.b047fdf8b69232317ff6b0c1fb687f74.png

  • Like 7
Link to comment
Share on other sites

3 hours ago, Guy Verville said:

Thank you. It is interesting. As we don't know if we will host the two sites, it can be tricky to get there. But I will give it a try!

Of course - that is a good reason to not use it. It was on Ryan's roadmap to allow it to work over http, but not sure when/if that will happen.

  • Like 1
Link to comment
Share on other sites

@adrian, @Guy Verville Thanks for your inputs. I tested WireHttp a little today and I must say that it's quite convenient, so I will use it. The beauty of PW, one tool for almost all tasks. 

$clantag = "test";
$token = "---";
$url = "https://site.com/" . urlencode($clantag);

$http = new WireHttp();
$http->setValidateURLOptions([
    'convertEncoded' => false,
    'encodeSpace' => true
]);
$http->setHeaders([
    'Accept' => "application/json",
    'Authorization' => "Bearer " . $token
]);

$response = $http->getJSON($url);
d($response);

 

  • Like 5
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...