sawarame/php-json-server
Composer 安装命令:
composer create-project sawarame/php-json-server
包简介
REST API that can use JSON format files.
README 文档
README
php-json-server is RESTful API with PHP. The data can be wrote json format, and you can easily set up RESTful API mock server.
Installation and Startup
Use Composer for installation and server start-up.
# install
$ composer create-project sawarame/php-json-server path/to/install
Once installed, You can startup php-json-server with PHP build-in server.
# Startup with PHP build-in server $ cd path/to/install $ composer run --timeout 0 serve
Then visit the site at http://localhost:8080/. If the welcome page is displayed, installation and startup are successful.
Prepare data
Save data file in the path below.
path/to/install/data/db/schema_name.json
The schema_name of file name is used to data name. The data name can be any name, and multiple datas can be saved under different name. There is a sample.json in the initial state.
[
{
"id": 1,
"name": "Red",
"code": "#ff0000"
},
{
"id": 2,
"name": "Green",
"code": "#00ff00"
},
{
"id": 3,
"name": "Blue",
"code": "#0000ff"
}
]
Data must wrote by array of json format. Data structure is arbitrary, but id column is required.
Read data
To get the data named schema_name, access below URL with GET method.
$ curl -X GET 'http://localhost:8080/schema_name'
Default data rows per page is 20. if you want to change it, use rows parameter.
$ curl -X GET 'http://localhost:8080/schema_name?rows=10'
How to change page is use page parameter.
$ curl -X GET 'http://localhost:8080/schema_name?page=2'
You can search by using the column name as the parameter.
$ curl -X GET 'http://localhost:8080/schema_name?name=Green'
Normally, When multiple parameters are specified, the search will be an AND condition.
If you want to search with OR condition, use or to search_type parameter.
$ curl -X GET 'http://localhost:8080/sample?name[]=Red&name[]=Green&search_type=or'
Response header
The response header contains information about paging.
| name | description |
|---|---|
| PJS-Total: | Total number of datas. |
| PJS-pages: | Total number of pages. |
| PJS-Rows: | Rows of current page. |
Find row
Example below receive the data that id column value is 123.
$ curl -X GET 'http://localhost:8080/schema_name/123'
Insert row
Use POST method for insert data.
$ curl -X POST 'http://localhost:8080/schema_name' \ -H 'Content-Type: application/json' \ --data-raw '{"name":"Gray","code":"#808080"}'
Created data will be returned.
{"id":4,"name":"Gray","code":"#808080"}
Update row
Use PUT method for update data.
$ curl -X PUT 'http://localhost:8080/schema_name/2' \ -H 'Content-Type: application/json' \ --data-raw '{"name":"Yellow","code":"#FFFF00"}'
Updated data will be returned.
{"id":2,"name":"Yellow","code":"#FFFF00"}
Delete row
Use DELETE method for delete data.
$ curl -X DELETE 'http://localhost:8080/schema_name/4'
Deleted data will be returned.
{"id":4,"name":"Gray","code":"#808080"}
sawarame/php-json-server 适用场景与选型建议
sawarame/php-json-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「api」 「restful」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sawarame/php-json-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sawarame/php-json-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sawarame/php-json-server 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
This is a restful api to onesignal.
A RESTful API package for the Laravel and Lumen frameworks.
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-05-04