Ravi Ranjan Singh
Ravi Ranjan Singh

Reputation: 819

Return JSOn data from a REST API in ColdFusion

I am trying to fetch JSON data from a ColdFusion site using a GET call and use the output JSON in an Android app. Wanting to start with a simple hello world component, but it is throwing error when accessed via browser. "Unsupported operation"

The cfc content is

<cfcomponent hint="A first CFC">
    <cffunction name="getValue" returntype="String" access="public">
        <cfreturn "Hello World">
    </cffunction>
</cfcomponent>

Where am I going wrong? Please guide.

Can someone provide link to a good example/tutorial for this please.

Upvotes: 2

Views: 1568

Answers (2)

Xin Zhang
Xin Zhang

Reputation: 58

returnFormat="JSON"? It seems you are handling directly on a raw string "HelloWorld". Therefore your frontend doesn't know how to operate the string as a valid JSON.

Upvotes: 1

Vlad
Vlad

Reputation: 1167

You can use Coldfusion component but since you are just starting to learn coldfusion component you can also use a simple cfm page to try and return the json in your android app. Create an index.cfm and save the code below. Then point the URL of your android app to the URL of the index.cfm example http://foo.bar/index.cfm

<cfcontent reset="true" >
<cfset msg = {} >
<cfset msg["message"] = "Hello World" >

<cfoutput>
     #serializeJSON(msg)#   
</cfoutput>

Upvotes: 1

Related Questions