【问题标题】:Request and Response Headers Override using Restler使用 Restler 覆盖请求和响应标头
【发布时间】:2013-03-24 14:44:30
【问题描述】:

我是restler的新手并尝试做以下事情,似乎无法掌握它

我通过 Restler 公开了这个类和方法

class Account {
    protected $Api_Version = array('version' => "1.0.2.1234", 'href' => "/");
// Returns the version of the service
// Content-Type: application/vnd.cust.version+json
function version() {
return json_encode($this->version);
}

// Accepts only Content Type: application/vnd.cust.account+json
function postCreate() {

}
}

1) 我想将我自己的 Content-Type 返回给客户端,就像在“版本”方法中一样,而不是默认的应用程序/json。就我而言,它的'application/vnd.cust.version+json'

2) 方法 postCreate 应该只在 Contet-Type 设置为 'application/vnd.cust.account+json' 时接受请求。如何检查请求中是否设置了该标头。

3) 同样在 restler API Explorer 中,对于方法名称,我怎样才能只显示方法名称而不是“version.json”。我只想显示“版本”,如方法名称

感谢您的帮助。 纳尔西

【问题讨论】:

    标签: restler


    【解决方案1】:

    1) 也许写你自己的格式?看一眼 http://restler3.luracast.com/examples/_003_multiformat/readme.html

    2) 您可以检查标题并在错误的标题上抛出异常。 看看这个链接 http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php

    3) 您是否尝试过将以下行添加到您的 Index.php 中?

    资源::$useFormatAsExtension = false

    希望能带你走得更远:)

    CU 英格

    【讨论】:

      猜你喜欢
      • 2016-08-06
      • 2016-05-06
      • 2021-09-19
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 2021-12-19
      • 2017-04-27
      • 2016-03-21
      相关资源
      最近更新 更多