0

What is the popular way to call external API in magento2? I see some use curl while others use ZendClient. Do you guys have the helper class that wraps ZendClient that I can take a look for an example of how to use that? I am new to magento 2 and cannot find a good documentation of ZendClient

I want to write a class that wraps ZendClient so the base_url can be shared and error will be handled properly.

1

I would recommend using \Magento\Framework\HTTP\ClientInterface

In some projects I have also used GuzzleHttp (\GuzzleHttp\Client) and also curl directly. If you have the latest version of Magento Guzzle will already be installed as it is required by Klarna.

4
  • What's difference between ClientInterface, ZendClient, Guzzle, Curl. Which one is the most used?
    –  coinhndp
    Jul 27 '20 at 12:58
  • @coinhndp ClientInterface is the Magento provided client wrapper and is currently implemented using curl, curl is the library used to make the raw request which a lot of other libraries "wrap" to simplify the process, ZendClient and Guzzle are some other wrappers. Guzzle is probably the most popular and has the ability to do multiple connections simultaneously as well as promise-based requests.
    – Craig
    Jul 27 '20 at 13:11
  • Great! I will go for Guzzle. Do you have any example of Guzzle code on github?
    –  coinhndp
    Jul 27 '20 at 13:13
  • @coinhndp Simple example here docs.guzzlephp.org/en/stable Do take a look at the promise/multiple request functionality, It could have really helped me in the past but I didn't have time but could be a real help possibly.
    – Craig
    Jul 27 '20 at 13:16
0

ZendClient has a problem with API response HTTP/2 https://github.com/magento/magento2/issues/19441 Guzzle is the safe choice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.