<!--- Resource expects: name: String age: Numeric (0 - 99) ---> <!--- Check to see if the name is supplied. ---> <cfif !structKeyExists( url, "name" )> <!--- Stop any further processing of this resource. ---> <cfthrow type="BadRequest" message="The Name attribute is missing from the request." errorcode="11011" /> </cfif> <!--- Validate name value. ---> <cfif ( !len( url.name ) || (len( url.name ) gt 40) || reFindNoCase( "[^a-z\s'-]", url.name ) )> <!--- Stop any further processing of this resource. ---> <cfthrow type="BadRequest" message="The Name attribute must be between 1 and 40 characters and may only contain letters, spaces, dashes, and apostrophes." errorcode="11012" /> </cfif> <!--- Check to see if age is supplied. ---> <cfif !structKeyExists( url, "age" )> <!--- Stop any further processing of this resource. ---> <cfthrow type="BadRequest" message="The Age attribute is missing from the request." errorcode="11021" /> </cfif> <!--- Validate age value. ---> <cfif ( !isNumeric( url.age ) || (url.age lt 0) || (url.age gt 99) )> <!--- Stop any further processing of this resource. ---> <cfthrow type="BadRequest" message="The Age attribute must be a number between 0 and 99 (inclusive)." errorcode="11022" /> </cfif> <!--- ----------------------------------------------------- ---> <!--- ----------------------------------------------------- ---> <!--- If we made it this far, the supplied resource attributes are valid. Now, let's create a fake resource for the demo. ---> <cfset request.response = {} /> <cfset request.response[ "id" ] = randRange( 1000, 9999 ) /> <cfset request.response[ "name" ] = url.name /> <cfset request.response[ "age" ] = url.age />