ndapio/rest-helper 问题修复 & 功能扩展

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

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

ndapio/rest-helper

Composer 安装命令:

composer require ndapio/rest-helper

包简介

A library that supports communication with REST API

README 文档

README

A library that supports communication with REST API. This library can speed up your development with REST API and make it easier to troubleshoot.

  • Built-in code base to interact with Guzzle to call REST API.
  • Built-in code to support Guzzle request under HTTP/HTTPS proxy.
  • Built-in code to get responded cookies.
  • Built-in code for common authentication method: username & password or access token
  • Built-in code to support form params, JSON data, XML data

Guide and sample

You can extend the RestApi class to use in your project.

Example:

<?php
use NDAPio\RestHelper\RestApi;
class SampleRestful extends RestApi {
    public function __construct($base_url = "https://sample.com") {
        $this->base_url = $base_url;
    }
    public function sample() {
        $args = array(
            "path" => "/path",
            "params" => array(
                "param_1" => "value_1",
            ),
            "headers" => array(
                "Header 1" => "Value 1"
            ),
            "data_type" => "json:json", // format: input:output of REST API
			// default if not defined: json:json
			// json:json => REST API endpoint gets json and returns json
			// form:json => REST API endpont gets form params (like HTTP Form post) and returns json
			// json:xml => REST API endpoint gets json and returns xml
			// form:xml => REST API endpont gets form params (like HTTP Form post) and returns xml
        );
        return $this->doGET($args); // doPOST, doPUT, doDELETE
    }
}
?>

Note: There are more samples in sample folder

Response

Success response:

array(  
  "status" => "success",  
  "time" => $timestamp,  
  "code" => $code,  
  "cookies" => $cookies,  
  "response" => $response_data_parsed // depend on the data_type input  
);

Error response:

$response = array(  
  "status" => "error",  
  "time" => $timestamp, 
  "code" => $code // 401, 403, 500, ... 
);

Exception response:

array(  
  "status" => "exception",  
  "code" => 000,  
  "time" => $timestamp,  
  "response" => array(  
      "message" => $exception_message,  
      "action" => $action,  
      "headers" => $headers,  
      "params" => $params,  
      "proxy" => $proxy  
  )  
);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固