承接 cdgco/php-rest-service 相关项目开发

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

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

cdgco/php-rest-service

最新稳定版本:v0.2.4

Composer 安装命令:

composer require cdgco/php-rest-service

包简介

PHP REST Service is a simple and fast PHP class for server side RESTful APIs.

README 文档

README

PHP REST Service

PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.

Build Status PHP Version Package Version License

https://cdgco.github.io/php-rest-service

Features

  • Easy to use syntax
  • Regular Expression support
  • Error handling through PHP Exceptions
  • JSON, XML, and plain text responses
  • Automatic OpenAPI specification generation
  • Parameter validation through PHP function signature
  • Can return a summary of all routes or one route through OPTIONS method based on PHPDoc (if OPTIONS is not overridden)
  • Support of GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS
  • Suppress the HTTP status code with ?_suppress_status_code=1 (for clients that have troubles with that)
  • Supports custom error handling, logging, access control and response formatting functions.
  • Supports ?_method=httpMethod as addition to the actual HTTP method.
  • With auto-generation through PHP's reflection

Requirements

  • PHP 7.4+ (Tested on PHP 7.4 - 8.2)

Installation

php composer require cdgco/php-rest-service

Demo

Manual Endpoint Creation

use RestService\Server;

Server::create('/')
  ->addGetRoute('test/(\D+)', function($param){
    return 'Yay!' . $param; // $param pulled from URL capture group
  })
  ->addPostRoute('foo', function($field1) {
    return 'Hello ' . $field1; // same as "return 'Hello ' . $_POST('field1');"
  })
  ->addGetRoute('use/this/name', function(){
      return 'Hi there';
  })
->run();

Automatic Endpoint Creation

namespace MyRestApi;

use RestService\Server;

class Admin {
  /*
   * @url /test/(\d+)
   */
  public function getTest($param) {
    return 'Yay!' . $param; // $param pulled from URL capture group
  }
  public function postFoo($field1){
    return 'Hello ' . $field1; // same as "return 'Hello ' . $_POST('field1');"
  }
  /*
   * @url /use/this/name
   */
  public function getNotThisName($field1){
    return 'Hi there';
  }
}

Server::create('/', 'myRestApi\Admin')
    ->collectRoutes()
->run();

Both methods will generate the following endpoints:

+ GET  /test/:param
+ POST /foo
+ GET  /use/this/name

Documentation

Read the full documentation at https://cdgco.github.io/php-rest-service.

License

Licensed under the MIT License. See the LICENSE file for more details.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 76
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固