Creating REST APIs in coldfusion

Other topics

Creating backend

<cfcomponent displayname="myAPI" output="false">
    <cffunction name="init" access="public" output="no">
        <!--- do some basic stuff --->
        <cfreturn this>
    </cffunction>

    <cffunction name="welcome">
        <cfreturn "Hello World!">
    </cffunction>
</cfcomponent>

The interface

<cfscript>
    api_request = GetHttpRequestData();
    api = createObject("component","myAPI").init();
</cfscript>

<cfif api_request.method is 'GET'>
    <cfoutput>#api.welcome()#</cfoutput>
<cfelseif api_request.method is 'POST'>
    <cfheader statuscode="500" statustext="Internal Server Error" />
</cfif>

Contributors

Topic Id: 10698

Example Ids: 32096,32097

This site is not affiliated with any of the contributors.