【发布时间】:2016-02-11 19:29:23
【问题描述】:
在 ColdFusion Lucee 上创建我的第一个 RestFul Web 服务。
这些是我遵循的步骤。
- 在 ROOT 上创建了名为“RestAPI”的文件夹
- 在 RestAPI/API 下创建子文件夹(用于 CFC)
- 已创建 CFC RestAPI/API/Hello.cfc
你好.cfc
<cfcomponent rest="true" restpath="/hello">
<cffunction name="formPost" access="remote" returnType="String" httpMethod="POST" restPath="/form">
<cfargument name="firstname" type="String" restArgSource="Form">
<cfargument name="lastname" type="String" restArgSource="Form">
<cfset res="firstname : " & #firstname# & " lastname : " & #lastname#>
<cfreturn res>
</cffunction>
</cfcomponent>
- 创建 CFM Call.cfm
调用.cfm
<cfhttp url="http://mydev:8888/rest/Example/hello/form" method="POST" result="res" port="8888">
<cfhttpparam type="formfield" name="firstname" value="Dan">
<cfhttpparam type="formfield" name="lastname" value="Bin">
- 在 lucee 管理服务器中创建了一个映射。
/Example
当我运行 Call.cfm 时,我得到了这个输出
在映射 [/Example] 中找不到 [/RestAPI/call.cfm] 的休息服务
【问题讨论】:
-
从您的屏幕截图看来,您已将
call.cfm模板放置在 RestAPI 路径mydev:8888/rest/RestAPI/call.cfm中。将其移至 webroot 并重试mydev:8888/call.cfm。 -
@Miguel-F 感谢您的回复 .. 我将 RestAPI/call.cfm 和 API 保存在 RestAPI 的子文件夹中。我不能保留 API 的根文件夹??
-
我只是指您调用 Rest 服务的
call.cfm文件。仅将该文件放在 webroot 中。然后从浏览器调用它mydev:8888/call.cfm。您所有的 cfc 都保留在RestAPI之下。 -
忽略我之前的评论。我想我现在明白你的意思了。所以改为尝试将其称为
mydev:8888/RestAPI/call.cfm。不要在调用 CFM 时包含/rest,但在调用服务时要包含/rest。 -
@Miguel-F 是的,它在根文件夹旁边工作,实际上它在除 RestAPI 文件夹之外的任何地方工作。我试图理解为什么会这样?尽管在我的情况下我没有将我的文件保存在组件文件夹中,但它是“API”。
标签: web-services rest coldfusion railo lucee