<cfcomponent extends="taffy.core.resource" taffy:uri="/contacts" taffy:mime="application/json">
<cffunction name="get">
<cfset var local = {} />
<cfquery name="local.qGetcontacts" datasource="#application.dsn#">
SELECT TOP 5 *
FROM contacts
</cfquery>
<cfreturn representationOf( local.qGetcontacts ) />
</cffunction>
</cfcomponent>
Client code:
<cfhttp method="get" url="http://api.myTestBox.net/API/index.cfm/contacts" result="getcontactsRet">
<cfhttpparam type="header" name="content-type" value="application/json"/>
</cfhttp>
<p><cfdump var="#getcontactsRet#"></p>
Response:
| struct | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Charset | [empty string] | ||||||||||||||||
| ErrorDetail | [empty string] | ||||||||||||||||
| Filecontent | Bad Request | ||||||||||||||||
| Header | HTTP/1.1 400 Your default mime type is not implemented Content-Type: text/html Date: Mon, 03 Jun 2013 17:21:35 GMT Server: Microsoft-IIS/7.0 X-Powered-By: ASP.NET | ||||||||||||||||
| Mimetype | text/html | ||||||||||||||||
| Responseheader |
| ||||||||||||||||
| Statuscode | 400 Your default mime type is not implemented | ||||||||||||||||
| Text | YES | ||||||||||||||||
<cfcomponent extends="taffy.core.api">
<cfscript>
this.name = hash(getCurrentTemplatePath());
variables.framework = {};
variables.framework.debugKey = "debug";
variables.framework.reloadKey = "reload";
variables.framework.reloadPassword = "true";
variables.framework.representationClass = "taffy.core.nativeJsonRepresentation";
variables.framework.returnExceptionsAsJson = true;
variables.framework.reloadOnEveryRequest = true;
// do your onApplicationStart stuff here
function applicationStartEvent(){
application.dsn = "testDSN";
}
// 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;
}
</cfscript>
</cfcomponent>
TIA,
Jose
--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.