Skip to sending parameter in ColdFusion REST Service

575 Views Asked by At

I was writing a REST component but having difficulties when I do not want to pass argument for a parameter. My code and URL (PATH style) look like this.

Component definition:

<cfcomponent rest="true" restPath="SearchRestAPI">
<cffunction name="restaurantResults" access="remote" httpMethod="get" 
            output="false" returntype="Query" produces="application/json"
            restPath="Search/{city : ([a-zA-Z])*}/{address}/{type}">

<cfargument name="city" default="" type="string" restargsource="path">
<cfargument name="address" default="" type="string" restargsource="path"> 
<cfargument name="type" default="" type="string" restargsource="path">

Calling URL/Path to consume the REST service. Notice I do not want to send any value for type parameter so there is double slash at the end of the path:

http://localhost:8502/backend/section/SearchResAPI/Search/Calcutta/Lindsay Street//

But this is throwing a "Not Found" error. Any suggestion would be highly appreciated.

1

There are 1 best solutions below

0
On

I am not sure about this ColdFusion functionality, but looks like "restPath" works with regular expressions (which you are already using when capturing the city parameter

([a-zA-Z])* // your city parameter matches the specified character sets zero or more times.

Similarly to the above, you could try:

restPath="Search/{city : ([a-zA-Z])*}/{address}/{type: ([a-zA-Z])*}"

Here is a ColdFusion page that has some examples as well (search the page for "restPath"): https://wikidocs.adobe.com/wiki/display/coldfusionen/cfcomponent