承接 adrotec/webapi-bundle 相关项目开发

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

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

adrotec/webapi-bundle

Composer 安装命令:

composer require adrotec/webapi-bundle

包简介

Create a JSON WebApi with minimum configuration, targetting several client side libraries, such as breeze js

README 文档

README

This project is no longer maintained. We will not be accepting pull requests, addressing issues, nor making future releases.

AdrotecWebApiBundle

This is a Symfony 2bundle to create Web APIs with breeze.server.php

Usage

Install with composer

    "require": {
      "adrotec/webapi-bundle": "dev-master",
      "symfony/validator": "dev-master"
    }

"symfony/validator": "dev-master" is required for validations with breeze.server.php to work properly

Enable the bundle in AppKernel.php

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new Adrotec\WebApiBundle\AdrotecWebApiBundle(),
        // ...
    );
}

The order is important here because AdrotecWebApiBundle overrides some of the JMSSerializerBundle behaviours. E.g: Naming strategy, Lazy loading, etc.

Create an API controller

Add routing configuration

# src/EmpDirectory/Bundle/Resources/config/routing.yml
emp_directory_api:
    path:       /api/{resource}
    defaults:   { _controller: EmpDirectoryBundle:Api:api }

the request parameter {resource} is important here, since it is used by the library to identify the current request resource.

The bundle exposes a service named adrotec_webapi which you can use in your controller.

// src/EmpDirectory/Bundle/Controller/ApiController.php

namespace EmpDirectory\Bundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ApiController extends Controller
{

    public function apiAction(Request $request)
    {
        $api = $this->container->get('adrotec_webapi');

        $api->addResources(array(
            'Employees' => 'EmpDirectory\Bundle\Entity\Employee',
            'Departments' => 'EmpDirectory\Bundle\Entity\Department',
            'Jobs' => 'EmpDirectory\Bundle\Entity\Job',
        ));
        
        // $request->attributes->set($request->attributes->get('resource'));

        $response = $api->handle($request);
        
        return $response;
    }

}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-07