i trying create new rest service in coldfusion , wanted try not passing in parameters if don't have value them getting 'not found' response function.
rest service cfc:
<cfcomponent rest="true" restpath="/crudservice"> <cffunction name="gethandlerjson" access="remote" httpmethod="get" restpath="{customerid}" returntype="query" produces="application/json"> <cfargument name="customerid" required="false" restargsource="path" type="numeric" default=-1/> <cfset myquery = querynew("id,name","integer,varchar",[[1, "sagar"], [2, "ganatra"]])> <cfquery dbtype="query" name="resultquery"> select * myquery 1=1 <cfif arguments.customerid neq -1> , id = #arguments.customerid# </cfif> </cfquery> <cfreturn resultquery> </cffunction> </cfcomponent>
and how calling it:
<cfhttp url="http://dev.test.com/rest/api/crudservice/2" result="restresult" method="get" /> <cfdump var="#deserializejson(restresult.filecontent,false)#">
and outcome:
{"columns":["id","name"],"data":[[2,"ganatra"]]}
what want able call service without id , of results back. need create separate function this? best practice?
when passing parameters rest service cfc via path params must exist in url. if not, path cf looking @ not correct.
i believe need separate function return results...or, pass huge number 1000000.
Comments
Post a Comment