ColdFusion comes bundled with added support for creating REST applications on websites via ColdFusion code. This is done by making ColdFusion components within your application REST-enabled. This article is designed to outline what is required to take advantage of the REST enabled services available in ColdFusion.
How to register a ColdFusion REST service in your web application
It is very simple to begin taking advantage of your own REST API in a ColdFusion web application. This can be done by utilizing the
restInitApplication method in your site’s
Application.cfc file. Below are tag and script based examples of this method.
skipCFCWithError : false,
useHost : true,
host : "website-name.com"
Once you’ve added this method to your Application.cfc you will then need to restart your application. This can be done by creating a CFM template that contains the following:
<cfset ApplicationStop() />
<cflocation url="index.cfm" addtoken="false" />
Note: The path to your REST enabled application will need to contain rest-enabled components in order for you to call your API. Additionally, all API requests will require two service mapping references. The one you specify in your ‘serviceMapping’ attribute along with the /REST/ mapping. All requests to /REST/ are handled by the ColdFusion connector which is responsible for mapping your web request to the service mapping you’re specifying.
For example: https://website-name.com/REST/test-api/ 10[component name]/[function name]/
In order to take advantage of my rest-enabled CFC I would have to include /REST/ and /test-api/ at the beginning of each request. From there you can reference your component path along with the function you’re wanting to invoke.
Congratulations! You have now created your first rest-enabled ColdFusion application and you can now begin taking advantage of your rest-enabled ColdFusion components. If you encounter any issues implementing a rest application on your website, then please feel free to contact our world class support team.