kelvinwongg/yapi 问题修复 & 功能扩展

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

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

kelvinwongg/yapi

Composer 安装命令:

composer require kelvinwongg/yapi

包简介

A single declarative yaml document crud api cms framwork, or whatever

README 文档

README

A zero-configuration, single declarative YAML document, HTTP CRUD API framwork.

Installation

Install YAPI in your project root via composer

composer require kelvinwongg/yapi

Usage

/api.yaml

openapi: 3.0.0

info:
  version: 1.0.0
  title: 'HR API'

paths:
  /employees:
    get:
      description: 'Obtain information about all employees from the HR database'
      parameters: 
        - name: bodyLimit
          in: query
          required: true
          description: The amount of employees returned
          schema:
            type: integer
            minimum: 10
            maximum: 20
            example: 15
        - name: pageLimit
          in: query
          # required: true
          description: The pages to return employees info
          schema:
            type: integer
            minimum: 1
            maximum: 5
            example: 2
      responses:
        200:
          description: Successful pull of employee info
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Employees'

components:
  schemas:
    Employees:
      description: 'Array of employee info'
      type: array
      items:
        $ref: '#/components/schemas/Employee'
    Employee:
      description: 'Model containing employee info'
      type: object
      properties:
        id:
          type: integer
          example: 4
        employee_name:
          type: string
          example: Ryan Pinkham
        employee_title:
          type: string
          example: Market Manager

/index.php

require_once __DIR__ . '/vendor/autoload.php';
$yapi = new \Yapi\Yapi('./api.yaml');

/paths/Employees.php

<?php

class Employees
{	
	public function get($file, $request, $response, $crudHook)
	{
		$response->setContent([
			[
				'id' => 1,
				'employee_name' => 'Steve Davis',
				'employee_title' => 'Staff'
			],
			[
				'id' => 2,
				'employee_name' => 'Ronnie Hart',
				'employee_title' => 'Admin'
			]
		]);
	}
}

Request

curl -L -X GET 'http://localhost/employees?bodyLimit=10'

Response

[
  {"id":1,"employee_name":"Steve Davis","employee_title":"Staff"},
  {"id":2,"employee_name":"Ronnie Hart","employee_title":"Admin"}
]

How it works

  1. YAPI is complying with OAS3.

  2. YAPI is all about a YAML file, You feed it with a YAML file, and it does things for you.

  3. Be it construct a database and create a RESTful API endpoints that does normal CRUD operation to the database.

  4. You can also hook into the endpoints and doing just whatever you want with your own programming languages, or opt-in to response to client with the methods provided by YAPI.

The Story

You want to quickly setup a API endpoint for some data. There are many ways and frameworks that does that. But the problem is, as a professional developer, you want to work straight into the business, not spending your life for a repetitive story from every frameworks that come across:

You've spending weeks or months on learning a new framwork, reading its documentations, testing and playing along. Then, for the deliverable, you write a RESTful endpoint that simply do CRUD operations from a database.

In fact this is most of the time in my career that I spent a lot of time (or months) on doing this whenever I go to a new company, just to simply store form data into a database, or even no one would bother reading this data later. And most of the study and learning are just mapping the new jargon or workflow into what you have learnt many time before.

Recently I went to a new job, and going the same process again. This time I have to tackle the poorly documented Drupal, and tried to use it as a CMS and a application framework for some custom JSON api. THe feeling of life-wasting came again, makes me want to quit. Then a thought blinks into my mind: Why cannot I write a YAML file that define a JSON api with simple CRUD operation, just like what I did with Docker and Kubernetes?

The YAPI project is just does that!

kelvinwongg/yapi 适用场景与选型建议

kelvinwongg/yapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 kelvinwongg/yapi 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2021-10-28