承接 bulton-fr/bfw-api 相关项目开发

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

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

bulton-fr/bfw-api

最新稳定版本:2.0.0-rc.11

Composer 安装命令:

composer require bulton-fr/bfw-api

包简介

API module for BFW

README 文档

README

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version License

Module to use an API with the BFW framework

Install :

You can use composer to get the module : composer require bulton-fr/bfw-api @stable

And to install the module : ./vendor/bin/bfwInstallModules

Config :

All config file for this module will be into app/config/bfw-api/. There are two files to configure (manifest.json is for the module update system).

First, the file config.php

  • urlPrefix : The prefix of all url used by the api.
  • useRest : If the API will use the REST format
  • useGraphQL : If the API will use the GraphQL format. But you can't use it for the moment, it's not implemented yet ! (issue #2)

Next, the file routes.php

It's all routes of your api. The prefix write into the other config file should not be added into the route url. To know the route format to use, please refer you to the exemple write into the routes.php config file.

Note : If not method is present, the route will respond to all http methods (get, set, put and delete).

Use it :

I will only explain to REST API because the GraphQL API is not implemented yet. I will update this section when it will implemented.

You will create you API class controllers into the directory /src/api/. All classes should extends the class \BfwApi\Rest class.

You will add a method for each used HTTP method for you controller. All datas receive from the request will be present into the property $datas. Il you want return an response, you can use the method sendResponsesendResponse(&$response). This method will automaticaly detect the response format to use (xml or json) from the HTTP request and convert your response to the correct format before sent it.

Example :

Configs :

return [
    'urlPrefix' => '/api',
    'useRest' => true,
    'useGraphQL' => false
];
return [
    'routes' => [
       '/books/{bookId:\d+}' => [
            'className' => 'Book',
            'method'    => ['GET', 'POST']
        ],
    ]
];

Controller class :

namespace Api;

class Book extends \BfwApi\Rest
{
    public function getRequest()
    {
        $returnedDatas = (object) [
            'elements' => (object) [
                'elemA' => [
                    0 => (object) [
                        'elemB' => 'Foo',
                        'elemC' => 'Bar'
                    ],
                    1 => (object) [
                        'elemB' => 'Foz',
                        'elemC' => 'Baz'
                    ]
                ]
            ]
        ];
        
        $this->sendResponse($returnedDatas);
    }
    
    public function postRequest()
    {
        $modele = new \Modeles\Books;
        //We consider to have some checks of the datas here.
        $status = $modele->updateBooks($this->datas);
        
        $response = (object) [
            'status' => $status,
        ];
        $this->sendResponse($response);
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2015-05-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固