xp-framework/rest 问题修复 & 功能扩展

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

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

xp-framework/rest

最新稳定版本:v10.0.0

Composer 安装命令:

composer require xp-framework/rest

包简介

REST Client and Server APIs for the XP Framework

关键字:

README 文档

README

Build Status on TravisCI XP Framework Module BSD Licence Required PHP 5.6+ Supports PHP 7.0+ Required HHVM 3.4+ Latest Stable Version

Client

Entry point

The Endpoint class serves as the entry point to this API. Create a new instance of it with the REST service's endpoint URL and then invoke its resource() method to work with the resources.

Creating: post

$api= new Endpoint('http://api.example.com/'); $response= $api->resource('users')->post(['name' => 'Test'], 'application/json'); // Check status codes if (201 !== $response->status()) { throw new IllegalStateException('Could not create user!'); } // Retrieve response headers $url= $response->header('Location');

Reading: get / head

$api= new Endpoint('http://api.example.com/'); // Unmarshal to object by optionally passing a type; otherwise returned as map $user= $api->resource('users/self')->get()->data(User::class); // Test for existance with HEAD $exists= (200 === $api->resource('users/1549')->head()->status()); // Pass parameters $list= $api->resource('user')->get(['page' => 1, 'per_page' => 50])->data();

Updating: put / patch

$api= new Endpoint('http://api.example.com/'); $resource= $api->resource('users/self') ->using('application/json') ->accepting('application/json') ; // Default content type and accept types set on resource used $updated= $resource->put(['name' => 'Tested', 'login' => $mail])->data(); // Resources can be reused! $updated= $resource->patch(['name' => 'Changed'])->data();

Deleting: delete

$api= new Endpoint('http://api.example.com/'); // Pass segments $api->resource('user/{id}', ['id' => 6100])->delete();

Execute

If you need full control over the request, use the generic execute() method.

use webservices\rest\Endpoint; use webservices\rest\RestRequest; use peer\http\HttpConstants; $api= new Endpoint('http://api.example.com/'); $request= (new RestRequest('/resource/{id}')) ->withMethod(HttpConstants::GET) ->withSegment('id', 5000) ->withParameter('details', 'true') ->withHeader('X-Binford', '6100 (more power)' ; $response= $api->execute($request); $content= $response->content(); // Raw data as string $value= $response->data(); // Deserialize to map

Deserialization

The REST API supports automatic result deserialization by passing a type to the data() method.

use com\example\api\types\Person; $person= $response->data(Person::class); $strings= $response->data('string[]'); $codes= $response->data('[:int]');

Authentication

Basic authentication is supported by embedding the credentials in the endpoint URL:

use webservices\rest\Endpoint; $api= new Endpoint('http://user:pass@api.example.com/');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固