A PHP package for make a request in easy way.
You can install this package using Composer, a popular PHP package manager:
composer require hilalahmad/http-client
- Send GET, POST, PUT, PATCH, and DELETE requests.
- Customize and set headers for your HTTP requests.
- Process JSON responses with built-in methods.
- Handle cURL errors and HTTP request errors gracefully.
Here's an example of how to use the HttpClient package to send a GET request:
use Hilalahmad\HttpClient\HttpClient;
$url="url of api";
$headers=[
'Authorization: Bearer your-token', // depend on you
'Content-Type: application/json',
]
$response = HttpClient::get($url, $headers);
$datas = HttpClient::getResponse($response);
foreach($datas as $data){
echo $data->id;
}
Here's an example of how to use the HttpClient package to send a GET request:
$response = HttpClient::get($url, $headers);
$datas = HttpClient::getResponse($response);
foreach($datas as $data){
echo $data->id;
}
Here's an example of how to use the HttpClient package to send a POST request:
$data=[
'value1'=>'1',
'value2'=>'2'
];
$response = HttpClient::post($url,$data, $headers);
$datas = HttpClient::getResponse($response);
print_r($datas);
Here's an example of how to use the HttpClient package to send a PATCH request:
$data=[
'value1'=>'1',
'value2'=>'2'
];
$response = HttpClient::patch($url,$data, $headers);
$datas = HttpClient::getResponse($response);
print_r($datas);
Here's an example of how to use the HttpClient package to send a PUT request:
$data=[
'value1'=>'1',
'value2'=>'2'
];
$response = HttpClient::put($url,$data, $headers);
$datas = HttpClient::getResponse($response);
print_r($datas);
Here's an example of how to use the HttpClient package to send a PUT request:
$response = HttpClient::delete($url, $headers);
$datas = HttpClient::getResponse($response);
print_r($datas);
If you'd like to contribute to this package or report issues, please check the Github repo for more details.
This package is open-source and is licensed under the MIT License.