承接 restful-template/response-template 相关项目开发

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

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

restful-template/response-template

Composer 安装命令:

composer require restful-template/response-template

包简介

A response interface builder for REST API

README 文档

README

A response interface builder for REST API.

Table of Contents

Installation

There are some installation ways. You can choose the best way for you.

Composer (recommended)

This way requires Composer:

$ composer require restful-template/response-template

Git

Clone the repo into your project:

$ git clone https://github.com/enriquerene/response-template.git

Zip

Dowload the package and uncpack it into your project: Dowload ZIP

Usage

ResponseTemplate requires an valid HTTP Status Code. Refer to section 10 of RFC 2616.

Simplest Case

The simplest case is to instantiate the class ResponseTemplate with HTTP Status Code "200 Ok." and call method build:

<?php
use RESTfulTemplate\ResponseTemplate;

$rest = new ResponseTemplate( 200 );
$response = $rest->build();
// $response contains following array:
// [
// 	"status" => [
// 		"code" => 200,
// 		"message" => "Ok."
// 	],
// 	"data" => null,
// 	"links" => [
// 		"self" => [
//			"url" => "https://example.com/",
//			"method" => "GET"
//		]
// 	]
// ];

Data in Response

It's possible insert data to response at the build moment:

<?php
use RESTfulTemplate\ResponseTemplate;

$product = [
	"id" => 1,
	"name" => "product-name",
	"displayName" => "Product Name",
	"price" => "14.50",
	"stock" => 20
];

$rest = new ResponseTemplate( 200 );
$response = $rest->build( $product );
// $response contains following array:
// [
// 	"status" => [
// 		"code" => 200,
// 		"message" => "Ok."
// 	],
// 	"data" => [
//		"id" => 1,
// 		"name" => "product-name",
// 		"displayName" => "Product Name",
// 		"price" => "14.50",
// 		"stock" => 20
// 	],
// 	"links" => [
// 		"self" => [
//			"url" => "https://example.com/products/1",
//			"method" => "GET"
//		]
// 	]
// ];

Links Setup

You can make use of setLink method to setup a link to response:

<?php
use RESTfulTemplate\ResponseTemplate;

$products = [
	[
		"id" => 1,
		"name" => "product-name",
		"displayName" => "Product Name",
		"price" => "14.50",
		"stock" => 20
	],
	/* ...more ones */
];

$rest = new ResponseTemplate( 200 );
$rest = $rest->setLink( "next", "https://example.com/products?page=2" );
$response = $rest->build( $products );
// $response contains following array:
// [
// 	"status" => [
// 		"code" => 200,
// 		"message" => "Ok."
// 	],
// 	"data" => [
//		[
//			"id" => 1,
//			"name" => "product-name",
//			"displayName" => "Product Name",
//			"price" => "14.50",
//			"stock" => 20
//		],
// 		/* ...more ones */
//	],
// 	"links" => [
// 		"self" => [
//			"url" => "https://example.com/products",
//			"method" => "GET"
//		],
// 		"next" => [
//			"url" => "https://example.com/products?page=2",
//			"method" => "GET"
//		]
// 	]
// ];

It's possible insert a third argument into setLink method to define "method" property of link. If you want work with a POST route, for example, you probrably would like to use $rest = $rest->setLink( "create", "/products", "POST" );.

Plan

This project aims to be up to date with standards. Future version may be aligned to RFC 7231. Some implementation in the roadmap:

Setting custom link key

  • If just the query string starting with ? is given, the same basename and path will be retrieved as in self url.
  • If just the path is given, the same basename will be retrieved as in self url.
  • If a basename including . is given, the same protocol will be retrieved as in self url.
  • Given full path including http/https protocol will be placed as it is into custom key url property.

Support

If you need some help you can open an issue.

Contribute

Do a pull request or send email to Support.

restful-template/response-template 适用场景与选型建议

restful-template/response-template 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「restful」 「http response」 「REST API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 restful-template/response-template 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 restful-template/response-template 我们能提供哪些服务?
定制开发 / 二次开发

基于 restful-template/response-template 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-10-30