IBM
IBM

Reputation: 252

ColdFusion Lucee Or Railo RestFull Webservice Mapping issue

Creating my first RestFul Webservice on ColdFusion Lucee.

These are the steps which I followed.

  1. Created folder on ROOT Named "RestAPI"
  2. Created sub-Folder under RestAPI/API (For CFC)
  3. Created CFC RestAPI/API/Hello.cfc

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>
  1. Created CFM Call.cfm

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">
  1. Created a mapping in lucee admin server. /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

Answers (1)

Miguel-F
Miguel-F

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

Related Questions