Does ColdFusion support REST API URIs with a dynamic token in the middle of the URI? -
i've been playing coldfusion 11's rest api support , wondering if it's possible have support uri dynamic token in middle of uri instead of @ end. is, supports uris like:
/rest/users/12345
where 12345
dynamic (in case, user's userid
). haven't been able find way (without tremendous amount of uri hacking) support uris like:
/rest/users/12345/emailaddresses
so, possible in coldfusion (11 or 2016)? if not, supported in taffy (i didn't see wrong)?
tia
it's been while , wanted provide answer in case else has same question...
coldfusion, when defining cfc rest endpoint, allows specify wildcards/variable names in restpath
attribute both <cfcomponent>
, <cffunction>
tags. define <cfargument>
tags each 1 of these variables can access them within function. example:
<cfcomponent rest="true" restpath="/users/{userid}/pets" ... > <cffunction name="getpets" access="remote" httpmethod="get"> <cfargument name="userid" type="numeric" required="true" restargsource="path" /> <!--- called path /users/123/pets/ ---> <!--- stuff using arguments.userid (123) variables ---> </cffunction> <cffunction name="getpet" access="remote" httpmethod="get" restpath="{petid}"> <cfargument name="userid" type="numeric" required="true" restargsource="path" /> <cfargument name="petid" type="numeric" required="true" restargsource="path" /> <!--- called path /users/123/pets/456/ ---> <!--- stuff using arguments.userid (123) and/or arguments.petid (456) variables ---> </cffunction> </cfcomponent>
the keys here using restpath
attribute variable defined variable name in curly braces , defining variables arguments function restargsource
attribute set "path".
i hope helps.
Comments
Post a Comment