简体   繁体   中英

REST not working on ColdFusion

I feel like I must be missing something obvious because the REST documentation seems so simple and the code I produced appears to work correctly unless I try to access it via REST.

hello.cfc:

component rest="true" restpath="restTest"{
    remote string function sayHello() httpMethod="get"{
        return "Hello World";
    }
}

Service Mapping:

I have tried both default yes and no with no change.

CFIDE服务映射

Test Page:

<html>
<head>
    <title>REST Test</title>
</head>
<body>
    Calling service as an object:<br>
    <cfset restTest = new hello() />
    <cfdump var="#restTest.sayHello()#" />
    <br>

    Calling service via http:<br>
    <cfhttp url="http://localhost/rest/restTest" result="restResult" method="GET" />
    <cfdump var="#restResult#" />
</body>
</html>

Results:

REST结果

Did you try accessing without directing the call through a connector/webserver? Keep your project inside /cfusion/wwwroot/ and then try accessing it via browser http://localhost:8500/rest/restTest

Sample test also worked for me after changing the URL

enter image description here

It seems like you are using a wrong URL when making HTTP request to the REST service. The URL should be like this:

http://{domain}/rest/{service mapping name}/{component level rest path}/{function level restpath}

So in your case the correct URL should be:

http://localhost/rest/api/restTest

For more info read this http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM