Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

REST API Implementation Using FW1 ColdFusion

HomeBlogREST API Implementation Using FW1 ColdFusion
ColdFusionRESTFW1

REST API Implementation Using FW1 ColdFusion

M
Post by MitrahsoftPublished: Mar 5, 2019

REST (REpresentational State Transfer), is an architectural style for providing standards for communicate between various computer applications (Web, Mobile, IoT..etc). REST API is the future and it is de facto standard in modern SPA (single page applications) applications. here it explains the implementation of REST API using FW1 framework. You might consumed various famous REST APIs (google maps API, PayPal API etc.,) in our applications. But building a RESTful web service, like other programming skills is part art. In this blog post, we are going to learn, how to build a RESTful web service using FW/1 framework in Adobe ColdFusion or Lucee. FW1 is a ColdFusion lightweight MVC framework developed by Sean Corfield.
Rest API Implementation Using Fw1 Coldfusion

Process

  • At first, You have to create a simple FW1 ColdFusion Application (just a skeleton app for FW/1 framework, to create this just extends your Application.cfc to FW/1 core cfc).
  • Add RESTful routes to the routes settings in your FW/1 framework. Adding RESTful routes is nothing but, you are making your component as a REST resource. In REST Architecture everything is a resource. Each and every REST URL points to a particular resource and the HTTP method determines what to do with that resource (eg. GET to get data, POST to create a new object, PUT/PATH to update, DELETE to drop a resource).

Application.cfc

cfml
component extends="framework.one" {

    THIS.name = hash( getCurrentTemplatePath() );

    variables.framework = {
        // whether to force generation of SES URLs:
        generateSES = true,

        // whether to omit /index.cfm in SES URLs:
        SESOmitIndex = true,

        decodeRequestBody = true,
        reloadApplicationOnEveryRequest = true,

        // routes (for fancier SES URLs) - see the documentation for details:
        routes = [
            { "$RESOURCES" = "myComponent" }
        ],

        routesCaseSensitive = false
    };

}

Here, 'mycomponent' is the controller name (cfc file name inside controllers folder) which you are going to use as an REST resource. Adding this simple setting means the following default settings.

cfml
{ "$GET/mycomponent/$" = "/mycomponent/default" },
{ "$GET/mycomponent/new/$" = "/mycomponent/new" },
{ "$POST/mycomponent/$" = "/mycomponent/create" },
{ "$GET/mycomponent/:id/$" = "/mycomponent/show/id/:id" },
{ "$PATCH/mycomponent/:id/$" = "/mycomponent/update/id/:id", "$PUT/mycomponent/:id/$" = "/mycomponent/update/id/:id" },
{ "$DELETE/mycomponent/:id/$" = "/mycomponent/destroy/id/:id" },
{ "$*/mycomponent/$" = "/mycomponent/error" }

Lets give a brief explaination for this. If your REST URL is pointing to mycomponent resource and the http method is GET then it will hit the default method in mycomponent.cfc. In the same way, If your REST URL is pointing to mycomponent resource and the http method is POST then it will hit the create method in mycomponent.cfc. From this, you can able to know clearly that your Resource (mycomponent.cfc) should contain the predefined methods (default, new, create, show, update, destroy). However, You can also able to overwrite these default routes & controller CFC method names.

cfml
{ "$GET/mycomponent/:id/$" = "/mycomponent/show/id/:id" }
{ "$PATCH/mycomponent/:id/$" = "/mycomponent/update/id/:id", "$PUT/mycomponent/:id/$"   = "/mycomponent/update/id/:id" }
{ "$DELETE/mycomponent/:id/$" = "/mycomponent/destroy/id/:id" }

myComponent.cfc

For these methods, passed 'id' value will be available in rc with the name relevant to their resource component(like mycomponent_id).

cfml
component accessors="true" {

	property employeeService;

	function init( any fw ) {
		variables.fw = fw;
		return this;
	}

	function default( struct rc, struct headers ) {

		// For getting all Employees Info
		var response = variables.employeeService.getEmployees();

		variables.fw.renderData()
			.type( 'json' )
			.data( response )
			.statusCode( 200 )
			.statusText( "Successfull" );
	}

	function show( struct rc, struct headers ) {

		// For getting selected Employee
		var response = variables.employeeService.getEmployees(
			argumentCollection = rc
		);

		variables.fw.renderData()
			.type( 'json' )
			.data( response )
			.statusCode( 200 )
			.statusText( "Successfull" );
	}

	function create( struct rc, struct headers ) {

		// For new Employee creation
		var response = variables.employeeService.newEmployeeCreate(
			argumentCollection = rc
		);

		variables.fw.renderData()
			.type( 'json' )
			.data( response )
			.statusCode( 200 )
			.statusText( "Successfull" );
	}

	function update( struct rc, struct headers ) {

		// For update selected Employee
		var response = variables.employeeService.updateEmployee(
			argumentCollection = rc
		);

		variables.fw.renderData()
			.type( 'json' )
			.data( response )
			.statusCode( 200 )
			.statusText( "Successfull" );
	}

	function destroy( struct rc, struct headers ) {

		// For delete selected Employee
		var response = variables.employeeService.deleteEmployee(
			argumentCollection = rc
		);

		variables.fw.renderData()
			.type( 'json' )
			.data( response )
			.statusCode( 200 )
			.statusText( "Successfull" );
	}

}

Here, renderData() is a FW1 framework helper method to bypass views and layouts completely and automatically return data rendered as JSON, XML, or plain text to your caller based on contentType mentioned in type chained method. Once you have called renderData(), you can do chain builder calls for the following methods to set their corresponding values.

  • data() to set the data payload to be rendered
  • type() to set the content type
  • header() to add an HTTP response header (this is an new feature in release 4.0)
  • statusCode() to set the HTTP status code
  • statusText() to set the HTTP status message (this is a new feature in release 4.0)
  • jsonpCallback() to set the JSONP callback

URL to access this endpoint

  • http://myapplication/index.cfm/mycomponent

Here, http://myapplication/index.cfm refers the path of your application and /mycomponent at the end refers the resource name (the name which we provided in { "$RESOURCES" = "mycomponent" }). As I mentioned earlier, based on the http method, it will call the corresponding method and render the data to the caller.

Get call sample

if run http://myapplication/index.cfm/mycomponent URL, it will be considered as get http method for getting collection of all resources and will access the corresponding default method to get the values.

Get call response

json
{
	"COLUMNS": [
		"EMPLOYEE_ID",
		"EMPLOYEE_NAME",
		"EMPLOYMENT_ID",
		"EMPLOYMENT_ID",
		"EMPLOYMENT_NAME",
		"EMPLOYMENT_TYPE",
		"UPDATED_TIME"
	],
	"DATA": [
		[1, "Prabha", 1, 1, "Marketting", "Self", "Oct 8 2018 11:08AM"],
		[2, "Bala", 1, 1, "Marketting", "Self", "Oct 8 2018 11:08AM"],
		[3, "Ganesa", 2, 2, "TeleComm", "Related", "2018-10-08 12:10:22.2780000 +00:00"],
		[4, "Sarvan", 2, 2, "TeleComm", "Related", "2018-10-08 12:10:22.2780000 +00:00"],
		[7, "Vignesh Babu", 2, 2, "TeleComm", "Related", "2018-10-08 12:10:22.2780000 +00:00"]
	]
}

Get single value sample

if run http://myapplication/index.cfm/mycomponent/{:id} URL, it will be considered as get call for a single resource and will access the corresponding show method in your controller to get the detais about that particular resource details.

Get single value response

json
{
	"COLUMNS": [
		"EMPLOYEE_ID",
		"EMPLOYEE_NAME",
		"EMPLOYMENT_ID",
		"EMPLOYMENT_ID",
		"EMPLOYMENT_NAME",
		"EMPLOYMENT_TYPE",
		"UPDATED_TIME"
	],
	"DATA": [
		[
			7,
			"Vignesh Babu",
			2,
			2,
			"TeleComm",
			"Related",
			"2018-10-08 12:10:22.2780000 +00:00"
		]
	]
}

Other methods

Other methods like post, patch and delete can be called like below CFML code, to test it or you can use tools like postman too to test those.

cfml
<!--- Insert functionality http call --->
<cfhttp url="http://myapplication/index.cfm/myComponent" method="post" result="myComponentInsert">
      <cfhttpparam name="name" type="formfield" value="Test for name">
      <cfhttpparam name="mycomponent_id" type="formfield" value="1">
</cfhttp>
<cfdump var="#myComponentInsert#" />

<!--- Update functionality http call --->
<cfhttp url="http://myapplication/index.cfm/myComponent/7" method="patch" result="myComponentUpdate">
       <cfhttpparam name="name" type="formfield" value="Vignesh Babu">
       <cfhttpparam name="mycomponent_id" type="formfield" value="2">
</cfhttp>
<cfdump var="#myComponentUpdate#" />

<!--- Delete functionality http call --->
<cfhttp url="http://myapplication/index.cfm/myComponent/6" method="delete" result="myComponentDelete">
       <cfhttpparam name="mycomponent_id" type="formfield" value="2">
</cfhttp>
<cfdump var="#myComponentDelete#" />

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers