Skip to content

hilalahmad0101/http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HttpClient PHP Package

A PHP package for make a request in easy way.

GitHub issues GitHub stars Total Downloads License

Table of Contents

Installation

You can install this package using Composer, a popular PHP package manager:

composer require hilalahmad/http-client

Features

  • 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.

Basic Usage

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;
}

Request Types

GET

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;
}

POST

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);

PATCH

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);

PUT

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);

DELETE

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);

Contribution

If you'd like to contribute to this package or report issues, please check the Github repo for more details.

License

This package is open-source and is licensed under the MIT License.

About

The HttpClient PHP package is a package designed for making HTTP requests using cURL.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages