lowem/easy-curl 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lowem/easy-curl

Composer 安装命令:

composer require lowem/easy-curl

包简介

Allow you to make requests to API end points easily

README 文档

README

Easy Curl

Status GitHub issues GitHub pull requests GitHub GitHub tag (latest SemVer)

This is a PHP wrapper for cURL

📝 Table of Contents

🧐 About

This project was created to help developers easily interact with the underlying cURL API.

🏁 Getting Started

These instructions will get you a copy of Easy Curl up and running.

Prerequisites

In order to install this package you have to install composer which can be done by following the steps based on your system here.

If you have not done so already run composer init in the root of your project directory, do so now to start using composer. Just follow the prompts as they appear.

Installing

To install Easy Curl run the command below while in your project root.

composer require lowem/easy-curl

Create a new PHP file and add the code below to the top of the file to automatically load in the package as well as any others you may have installed. The use statement prevents you from having to type in the full namespace of the package.

require_once "vendor/autoload.php";
use Lowem\EasyCurl\EasyCurl;

🎈 API Usage

GET Request get(header)

  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
    try {
      $test->get();
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

POST Request post(postFields, header)

  • postFields: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.
    • Example:
      [
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ]
  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
    try {
      $data = [
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ];
      $test->post(json_encode($data), [
        "Content-type: application/json; charset=UTF-8",
      ]);
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

PUT Request put(postFields, header)

  • postFields: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.
    • Example:
      [
        "id" => 1,
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ]
  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
    try {
      $data = [
        "id" => 1,
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ];
      $test->put(json_encode($data), [
        "Content-type: application/json; charset=UTF-8",
      ]);
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

DELETE Request delete()

    Example Usage:

$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
try {
  $test->delete();
} catch (HTTPRequestException $e) {
  echo $e->getCustomMessage();
}
print_r($test->getExecMessage());

$test->close();

✍️ Authors

See also the list of contributors who participated in this project.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固