承接 zlob/php-json-server 相关项目开发

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

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

zlob/php-json-server

Composer 安装命令:

composer require zlob/php-json-server

包简介

simple REST API json server

README 文档

README

Easy to use library, that provides you REST API server in a few minutes. Created for front-end developers who need a quick back-end for prototyping. May be used with you lovely php web framework

Inspired by JSON Server

NOT FOR PRODUCTION

Latest Stable Version Total Downloads License Build Status

Install

via composer: composer require zlob/php-json-server

##Example

You can use this library with any php web framework. Here is example how to integrate it with Laravel 5.1:

  • First, you need to create controller, where we will use php-json-server:
<?php

namespace App\Http\Controllers;

use Request;
use Response;
use Config;
use JsonServer\JsonServer;

class JsonServerController extends Controller
{
    public function handleRequest($uri)
    {
        $data = Request::all();                                             //request data
        $method = Request::method();                                        //request method
        $jsonServer = new JsonServer();                                     //create new JsonServer instance
        $response = $jsonServer->handleRequest($method, $uri, $data);       //handle request
                                                                            //return Symfony\Component\HttpFoundation\Response
                                                                            //object with content, status and headers
        $response->send();                                                  //send response
    }
}
  • Then, add to routes.php file new route, to link '/api/*' route with our controller method handleRequest
Route::any('api/{all}', "JsonServerController@handleRequest")->where('all', '.*');
  • Finaly, we can optionaly fill our database with some data. To do this, open php-json-server/db/db.json file and add some data:
{
    "posts": [
        {
            "id": 1,
            "title": "json-server",
            "author": "zlob"
        },
        {
            "id": 2,
            "title": "json-server",
            "author": "zlob"
        }
    ],
    "comments": [
        {
            "id": 1,
            "body": "some comment",
            "post_id": 1
        }
    ]
}
  • Thats all! Now, if you go to "/api/posts" you'll get { "id": 1, "title": "json-server", "author": "zlob" }

Based on the previous db.json file, here are all routes:

GET    /posts
GET    /posts/1
GET    /posts/1/comments
POST   /posts
PUT    /posts/1
PATCH  /posts/1
DELETE /posts/1

To filter resources

GET /posts?title=json-server&author=zlob

To slice resources, add _start and _end or _limit(an X-Total-Count header is included in the response).

GET /posts?_start=20&_end=30
GET /posts/1/comments?_start=0&_end=30

To sort resources, add _sort and _order (ascending order by default).

GET /posts?_sort=views&_order=desc
GET /posts/1/comments?_sort=votes&_order=asc

To make a full-text search on resources, add _query.

GET /posts?_query=internet

To embed other resources, add _embed(separate by ',' for more then one resources).

GET /posts/1?_embed=comments
GET /posts/1?_embed=comments,tags

CLI: Generate random data

You can fill database with fake data in one command. In example, to create table posts, with 50 resources, that contains fields title, date, author and content, in jsonServer directory use command:

php-json-server faker posts 'title.text date.date author.name content.text.10' --num=50

Where where fields separated by space, and field name, field type and additional parameter separated by '.' Field type and parameters described in faker, that used inside.

License

MIT - Zlob

zlob/php-json-server 适用场景与选型建议

zlob/php-json-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 226 次下载、GitHub Stars 达 27, 最近一次更新时间为 2015 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 zlob/php-json-server 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 27
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-20