1. Go to this page and download the library: Download amsify42/php-curl-http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amsify42 / php-curl-http example snippets
$curlHttp = new Amsify42\CurlHttp\CurlHttp('http://www.sample.com/users');
$curlRequest = new Amsify42\CurlHtpp\Request();
$curlRequest->setMethod('POST');
/**
* Set one of the header as Content-Type: application/json if you want to pass bodyData as json
*/
$curlRequest->setHeaders(['Content-Type: application/json']);
$curlRequest->setData(['name' => 'test', 'salary' => 123]);
$curlHttp = new Amsify42\CurlHttp\CurlHttp('http://www.sample.com/user/create', $curlRequest);
$curlRequest->setMethod('PUT');
$curlRequest->setHeaders(['Authorization: Bearer sf23rsdf23fds']);
/**
* Set request ContentType as json if you want to pass bodyData as json
*/
$curlRequest->setContenType('json');
$curlRequest->setData(['name' => 'test', 'salary' => 123]);
/* To get the response code */
$response->getCode();
/* To get the response body data */
$response->getBodyData();
/* To get the response headers as array */
$response->getHeaders();
/* To get the json decoded data of response */
$response->json();