234 attempt to fix js error Uncaught SyntaxError: Unexpected identifier 'hidden'
This commit is contained in:
+32
-32
@@ -12,7 +12,7 @@ The REST Web Service framework for ColdFusion and Lucee
|
||||
|
||||
**Application.cfc:**
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component extends="taffy.core.api" {}
|
||||
```
|
||||
|
||||
@@ -24,7 +24,7 @@ component extends="taffy.core.api" {}
|
||||
|
||||
**/resources/hello.cfc:**
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component extends="taffy.core.resource" taffy_uri="/hello" {
|
||||
|
||||
function get(){
|
||||
@@ -77,13 +77,13 @@ You can see that the taffy folder is a sibling to Application.cfc. This allows A
|
||||
|
||||
Next, if your Application.cfc and `/resources/` folder aren't in the web-root (e.g. they're inside something like `/api/`) then you'll need to add an [application-specific mapping](http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=appFramework_04.html) for `/resources` so that Taffy can find your resources to initialize the routes.
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
this.mappings["/resources"] = expandPath("./resources");
|
||||
```
|
||||
|
||||
You'll also need to add a mapping for `/taffy` so that the resources can extend `taffy.core.resource` (since the taffy folder isn't a child of the resources folder):
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
this.mappings["/taffy"] = expandPath("./taffy");
|
||||
```
|
||||
|
||||
@@ -132,7 +132,7 @@ In the xml above you can see that I only have 1 wildcard, but to compensate I've
|
||||
|
||||
Taffy allows for setting the HTTP status message using [.withStatus()](#withstatus), such as:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return representationOf({...}).withStatus(403, "Not Authorized");
|
||||
```
|
||||
|
||||
@@ -221,7 +221,7 @@ If you want a resource not to be included in the dashboard, set `taffy:dashboard
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component taffy_uri="/secret-squirrel" taffy_dashboard_hide {
|
||||
}
|
||||
```
|
||||
@@ -251,7 +251,7 @@ The **taffy:uri** property applies to the `<cfcomponent>` tag or the `component{
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component taffy_uri="/artist/{artistId}" {
|
||||
}
|
||||
```
|
||||
@@ -282,7 +282,7 @@ By convention, resources will automatically map the 4 primary HTTP REST verbs --
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function getUser( numeric userId ) taffy_verb="get" {
|
||||
}
|
||||
```
|
||||
@@ -298,7 +298,7 @@ You can prevent a resource from showing in the documentation by adding the `taff
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component extends="taffy.core.resource" taffy_uri="/artist/{artistId}" taffy_docs_hide {
|
||||
}
|
||||
```
|
||||
@@ -314,7 +314,7 @@ Similarly, you can hide methods and parameters by adding the attribute to the `<
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
public function getUser(
|
||||
required numeric userId,
|
||||
string _hidden = "" taffy_docs_hide
|
||||
@@ -339,7 +339,7 @@ By convention, the mime-types supported by your API are determined by the method
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function getAsJson() taffy_mime="application/json" {
|
||||
}
|
||||
```
|
||||
@@ -358,7 +358,7 @@ When your API supports more than one data format (i.e. json and xml), you must s
|
||||
|
||||
or
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function getAsJson() taffy_mime="application/json" taffy_default="true" {}
|
||||
|
||||
function getAsXml() taffy_mime="application/xml" {}
|
||||
@@ -368,7 +368,7 @@ function getAsXml() taffy_mime="application/xml" {}
|
||||
|
||||
Default values:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
variables.framework = {
|
||||
reloadKey = "reload",
|
||||
reloadPassword = "true",
|
||||
@@ -529,7 +529,7 @@ The allowed verbs, of course, are the ones allowed by the requested resource, as
|
||||
|
||||
In addition, as of Taffy 3.1.0, you can set this setting to a string of allowable hosts, as a (comma, semicolon, or space) delimited list:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
variables.framework.allowCrossDomain =
|
||||
"http://example.com; http://foo.bar, http://google.com";
|
||||
```
|
||||
@@ -589,7 +589,7 @@ Global headers are static. You set them on application initialization and they d
|
||||
|
||||
**NOTE FOR EXTERNAL BEAN FACTORY USERS (e.g. Coldspring, DI/1 etc)** If your external bean factory is initialized in onApplicationStart then you need to set the variables.framework.beanFactory after your bean factory has initialized, for example:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
component extends="taffy.core.api"
|
||||
{
|
||||
this.name = 'myapi';
|
||||
@@ -651,7 +651,7 @@ Taffy calls this method during initialization to determine in which configured e
|
||||
|
||||
The returned value will be used to load environment-specific configuration. For example, if you have the following code in your Application.cfc, then the dashboard will be disabled in production:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
variables.framework = {
|
||||
|
||||
disableDashboard = false
|
||||
@@ -702,13 +702,13 @@ This method is optional, and allows you to inspect and potentially abort an API
|
||||
|
||||
If you do not return TRUE, allowing the request to continue as normal, then Taffy expects you to call and return the result of either **[noData()](#nodata)** or **[representationOf()](#representationof)**. If you simply want to return with a status code of 403 (which indicates "Not Allowed") and no response body, you could do this:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return noData().withStatus(403);
|
||||
```
|
||||
|
||||
Alternately, you could return some data to indicate that they owe you money or something:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return representationOf({
|
||||
error="Your account is past due. Please email accounts payable."
|
||||
})
|
||||
@@ -719,7 +719,7 @@ The options here are limited only by your imagination.
|
||||
|
||||
You can add data to the **requestArguments** structure and this will be passed on to any resource that handles the request. Simply add a key to the structure:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function onTaffyRequest(
|
||||
verb,
|
||||
cfc,
|
||||
@@ -736,7 +736,7 @@ function onTaffyRequest(
|
||||
|
||||
In your resource:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function get(myData) {
|
||||
//arguments.myData => "myValue"
|
||||
}
|
||||
@@ -744,13 +744,13 @@ function get(myData) {
|
||||
|
||||
You can use the method metadata for anything you see fit; but the original use case was for role-based security. Consider the following resource method:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
public function getData( id ) taffy_method="get" role="datareader" { ... }
|
||||
```
|
||||
|
||||
Taffy doesn't do anything with the **role** metadata on this method other than expose it to you in onTaffyRequest. So let's use the user's API key to find out what roles they have, and verify that the method's required role is among them. This is a snippet from your Application.cfc:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
function onTaffyRequest(verb, cfc, requestArgs, mime, head, methodMetadata){
|
||||
|
||||
local.user = (...); //get user from api key...
|
||||
@@ -837,7 +837,7 @@ Resource CFCs extend `taffy.core.resource`. The following methods are available
|
||||
|
||||
This is a convenience method used to make sure that certain all-numeric inputs get serialized as a string in the output not converted to numeric output. Examples are postal codes or phone numbers.
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return rep(
|
||||
queryToArray(myQuery, function (row) {
|
||||
row.phone = encode.string(row.phone);
|
||||
@@ -853,7 +853,7 @@ return rep(
|
||||
|
||||
This method allows you to specify that there is no data to be returned for the current request. Generally, you would use it in conjunction with the **withStatus** method to set a specific return status for the request. For example, if the requested resource doesn't exist, you could return a 404 error like so:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return noData().withStatus(404);
|
||||
```
|
||||
|
||||
@@ -869,7 +869,7 @@ This method transforms a ColdFusion query object into an array of structures. It
|
||||
|
||||
The callback function can be used to efficiently transform keys in the structure before it is added to the array without additional looping. For example, you can use it to format dates in a particular style. **Your callback must return a value.**
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
queryToArray(someQ, function (row) {
|
||||
row.startDate = dateFormat(row.startDate, "yyyy-mm-dd");
|
||||
return row;
|
||||
@@ -878,7 +878,7 @@ queryToArray(someQ, function (row) {
|
||||
|
||||
When you want to return the resulting array as your API response, you must still wrap it in a [representationOf](#rep-1) call:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return rep(queryToArray(someQ));
|
||||
```
|
||||
|
||||
@@ -896,7 +896,7 @@ This method transforms a ColdFusion query object into a structure. If there is m
|
||||
|
||||
The callback function is passed the column name and the value, and can be used to efficiently transform keys in the structure as they are read from the query without need for additional looping. For example, you can use it to format dates in a particular style. **Your callback must return a value.**
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return queryToStruct(someQ, function (colName, val) {
|
||||
if (colName == "startDate") {
|
||||
return dateFormat(val, "yyyy-mm-dd");
|
||||
@@ -944,7 +944,7 @@ If you don't configure a logging adapter, the default is LogToEmail, but the def
|
||||
|
||||
Use this method in place of `representationOf()` to return a stream of binary data. Useful for streaming things like dynamically generated PDFs. **Note: ** When streaming binary data as the response, you must set the mime type manually using [withMime()](#withmime). For example:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return streamBinary(local.pdf).withStatus(200).withMime("application/pdf");
|
||||
```
|
||||
|
||||
@@ -957,7 +957,7 @@ return streamBinary(local.pdf).withStatus(200).withMime("application/pdf");
|
||||
|
||||
Use this method in place of `representationOf()` to stream a file from disk (or VFS). Optionally append `.andDelete( true )` to delete the file once streaming is complete. **Note: ** When streaming binary data as the response, you must set the mime type manually using [withMime()](#withmime). For example:
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return streamFile("/foo.txt")
|
||||
.andDelete(true)
|
||||
.withStatus(200)
|
||||
@@ -982,7 +982,7 @@ Use this method in place of `representationOf()` to stream an image from disk (o
|
||||
|
||||
This special method _**requires**_ the use of either **noData** or **representationOf**. It adds custom headers to the return. Additional use of **withStatus** optional.
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return representationOf(myData).withHeaders({"X-POWERED-BY"="Taffy 2.0!"});
|
||||
```
|
||||
|
||||
@@ -995,7 +995,7 @@ return representationOf(myData).withHeaders({"X-POWERED-BY"="Taffy 2.0!"});
|
||||
|
||||
This special method _**requires**_ the use of either **streamFile** or **streamBinary**. It overrides the default mime type header for the return.
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return streamFile("kittens/cuteness.pdf").withMime("application/pdf");
|
||||
```
|
||||
|
||||
@@ -1011,7 +1011,7 @@ This special method _**requires**_ the use of either **noData** or **representat
|
||||
|
||||
_If you do not specify a return status code, Taffy will always return status code 200 (OK) by default._
|
||||
|
||||
```js
|
||||
```cfscript
|
||||
return noData().withStatus(404, "Not Found");
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user