承接 hilalahmad/http-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hilalahmad/http-client

最新稳定版本:1.0.0

Composer 安装命令:

composer require hilalahmad/http-client

包简介

The HttpClient PHP package is a package designed for making HTTP requests using cURL. This package simplifies the process of sending GET, POST, PUT, PATCH, and DELETE requests, along with the ability to set custom headers, to external APIs or web services.

README 文档

README

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.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-07