coldfusion
REST API's maken in coldfusion
Zoeken…
Invoering
REST API's zijn interessant wanneer gegevens overal toegankelijk moeten zijn, inclusief verschillende talen (server- en clientzijde). Dat vereist scheiding van gegevens en verwerking.
Backend maken
<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>
De 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>
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow