How to use php curl as best practice in magento 2 ?

In Magento 2, We can get details about curl from Curl.php file at location Magento\Framework\HTTP\Adapter\Curl.

Magento gives native functionality for CURL instead of using default php curl_init().
We can send a request to third party services using curl by below way,

Curl with POST request data, we need to pass \Zend_Http_Client::POST,
Curl with PUT request data, we need to pass \Zend_Http_Client::PUT,
and for CURL with GET Request pass \Zend_Http_Client::GET argument in below function.

In Php file, I h ave given example code for Uses of GET, POST and PUT restĀ API call.

Most of the Developer used Curl Request in Magento 2 by Default PHP curl_init() way, Its Native PHP code and In Magento 2 We need to use Standard Magento Format Curl Request for GET,POST and PUT Call.

Below is plain PHP curl request code,

Leave a Reply

Your email address will not be published. Required fields are marked *