icodr8/contao-restful-webservices

此包已被弃用,不再维护。作者建议使用craffft/contao-restful-webservices包。

Contao OpenSource CMS的RESTful Webservices

安装: 5

依赖: 0

建议: 0

安全: 0

星标: 6

关注者: 4

分支: 2

开放问题: 1

类型:contao-module

2.1.0 2015-02-20 20:30 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:31:28 UTC


README

"RESTful Webservices"扩展是开发者实现自定义扩展中RESTful webservices的辅助库

许可证

此Contao扩展受LGPLv3许可证条款的约束。https://gnu.ac.cn/licenses/lgpl-3.0.html

依赖

链接

https://contao.org/en/extension-list/view/restful-webservices.html

文档

定义webservice "categories"(分类)

// systems/modules/mymodule/config/config.php

$GLOBALS['RESTFUL_WEBSERVICES']['ROUTING']['categories'] = array
(
    // Define the webservice location (required definition)
    // Callable via http://localhost/mycontao/interface/categories/12/my_token
    'pattern' => '/categories/{id}/{token}',

    // Restrict methods (optional definition)
    // You can use GET, PUT, POST and DELETE
    'methods' => array('GET', 'POST'),

    // Set requirements for the pattern values (optional definition)
    'requirements' => array
    (
        'id' => '\d+',
    ),

    // Restrict access by tokens (optional definition)
    'tokens' => array
    (
        'my_token',
    ),

    // Restrict access by ip addresses (optional definition)
    'ips' => array
    (
        '127.0.0.1',
    ),

    // Restrict CORS access by ip addresses (optional definition)
    'cors' => array
    (
        '192.168.1.180',
    )
);

声明webservice类"WebserviceCategories"(Webservice分类)

// systems/modules/mymodule/webservices/WebserviceCategories.php

namespace MyAppNamespace;

use \Haste\Http\Response\JsonResponse;

class WebserviceCategories extends \RESTfulWebservices\RESTfulController
{
    public function get()
    {
        $arrData = array();

        // Add "Hello World!" to the json output
        $arrData['status'] = 'Hello World!';

        // Send response
        $objResponse = new JsonResponse();
        $objResponse->setContent($arrData, JSON_PRETTY_PRINT);
        $objResponse->send();
    }

    public function put()
    {
        // Code for PUT requests
    }

    public function post()
    {
        // Code for POST requests
    }

    public function delete()
    {
        // Code for DELETE requests
    }
}