2

这是我尝试使用查询参数创建 REST 端点的代码片段,

<cfcomponent rest="true" restpath="api"> 
   <cffunction name="getUsersQuery" restpath="Users?filter={query}" access="remote" returntype="struct" httpmethod="GET" produces="application/json">
      <cfargument name="query" type="any" required="yes" restargsource="query" />
    
      <cfset var response = {} />
      <cfset response["message"] = "Test" />
      <cfreturn response>
  </cffunction>
</cfcomponent>

但是当我尝试像下面这样调用终点时,它会给出“不允许的方法”

http://localhost:8010/rest/v1/api/Users?filter=userName eq "test"

任何帮助将不胜感激。

4

1 回答 1

1

由于您在参数中提到过,因此您无需?filter={query}在其余路径中提供。restargsource="query"参数名称也应该是 URL 键值。

<cffunction name="getUsersQuery" restpath="Users" access="remote" returntype="struct" httpmethod="GET" produces="application/json">
   <cfargument name="filter" type="any" required="yes" restargsource="query" />
    
   <cfset var response = {} />
   <cfset response["message"] = "Test" />
   <cfreturn response>
</cffunction>
于 2020-10-07T17:07:31.873 回答