<cfcomponent extends="taffy.core.api">
<cfscript>
// do your onApplicationStart stuff here
function applicationStartEvent(){
application.DSN = "MyDSN";
}
// do your onRequestStart stuff here
function requestStartEvent(){}
// this function is called after the request has been parsed and all request details are known
function onTaffyRequest(verb, cfc, requestArguments, mimeExt){
// this would be a good place for you to check API key validity and other non-resource-specific validation
return true;
}
// called when taffy is initializing or when a reload is requested
function configureTaffy(){
setDebugKey("debug");
setReloadKey("reload");
setReloadPassword("true");
// Usage of this function is entirely optional. You may omit it if you want to use the default representation class.
// Change this to a custom class to change the default for the entire API instead of overriding for every individual response.
setDefaultRepresentationClass("taffy.core.genericRepresentation");
}
</cfscript>
</cfcomponent>
UserMember.cfc
<cfcomponent extends="taffy.core.resource" taffy:uri="/user/{UserID}" hint="">
<cffunction name="Get" access="public" output="false">
<cfargument name="UserID" required="yes" type="string">
<cfquery name="selUser" datasource="#application.DSN#">
SELECT *
FROM [User]
WHERE UserID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.UserID#" />
</cfquery>
<cfif selUser.recordCount gt 0>
<cfreturn representationOf(selUser).withStatus(200) />
<cfelse>
<cfreturn noData().withStatus(404) />
</cfif>
</cffunction>
</cfcomponent>
It's fairly vanilla code. Once I can get the application variable to output correctly I plan on storing a reference to several of my CFCs in the application scope.