Reputation: 252
Creating my first RestFul Webservice on ColdFusion Lucee.
These are the steps which I followed.
Hello.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>
Call.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">
/Example
When I run the Call.cfm I am getting this output
no rest service for [/RestAPI/call.cfm] found in mapping [/Example]
Please see the attached screen shots
Just want to know why it is not working in root folder
Upvotes: 3
Views: 1347
Reputation: 13548
From your initial screenshot I found that the issue seems to be how you are calling your call.cfm
template. The error message being reported is:
no rest service for [/RestAPI/call.cfm] found in mapping [/Example]
That tells me that it is looking for a service through your REST API instead of simply calling the template. I think this is because you referenced your call.cfm
template using /rest/
in the URL. Again from the screenshot I saw this in your browser's address bar:
mydev:8888/rest/RestAPI/call.cfm
This is when I suggested moving your call.cfm
template out of that sub-folder and into the web root. However, I think it will also work if you reference it correctly when the call.cfm
file is contained in your /RestAPI/
folder. You should be able to reference it like so:
mydev:8888/RestAPI/call.cfm
Notice that I have removed the /rest/
reference from this URL for the browser request. You do still need the /rest/
reference within your <cfhttp>
call though.
one last question please answer in answer box. i can keep multiple component (cfcs) files in one folder & map?
Yes you can keep multiple CFCs within your API folder.
Upvotes: 1