diff --git a/docs/collection.markdown b/docs/collection.markdown index f5f27d4..675bba2 100644 --- a/docs/collection.markdown +++ b/docs/collection.markdown @@ -6,7 +6,7 @@ A Collection resource allows client apps to save and query data. After creating a Collection resource in the dashboard, you can set up the schema that will automatically validate data sent to the resource url over HTTP. You can configure this schema in the dashboard. -The grid view below the property list allows you to edit the Collection manually. +The Data view in the dashboard allows you to edit the Collection manually. ## Property types @@ -84,14 +84,12 @@ A GET request at an object's URL will return the properties of that object: ## Updating an object -A PUT (or POST) request at an object's URL will update the object. You must include all properties except for `_id`. +A PUT (or POST) request at an object's URL will update the properties specified on the object. PUT /people/4f71fc7c2ba744786f000001 Content-Type: application/json { - "age": 24, - "firstName": "Fred", - "lastName": "Smith" + "age": 24 } The server will respond with the entire object: @@ -145,10 +143,11 @@ The `q` parameter supports [MongoDB's query language](http://www.mongodb.org/dis You can attach micro-scripts to events to add logic and validation to your objects. Collections currently support the following events: - * **On Get** - called when data is read - * **On Post** - called when data is created - * **On Put** - called when data is updated - * **On Delete** - called when data is destroyed + * **On GET** - called when data is read + * **On Validate** - called before creating or updating an object. + * **On POST** - called when data is created + * **On PUT** - called when data is updated + * **On DELETE** - called when data is destroyed ## Reading and setting properties @@ -156,17 +155,19 @@ In an event micro-script, the `this` object refers to the current object, and ha You can set values on the `this` object during an On Post or On Put event. These changes will be saved to the database. - // On Post: + // On POST: this.dateCreated = new Date(); - // On Put: + // On Validate: this.totalScore = this.level1Points + this.level2Points; +**Note**: If you intend for a property to be "automatic" (calculated by the server, and never provided by the client), you will need to mark it as **Optional** in the dashboard. + ## Accessing the current user If the request is coming from a logged in User, you can use the "me" object to access their properties. - // On Post: + // On POST: this.creator = me._id; @@ -174,7 +175,7 @@ If the request is coming from a logged in User, you can use the "me" object to a You can stop any event by calling the `cancel(message, [code])` method. - //On Delete: + //On DELETE: if (this.protected) { cancel('This post is protected and cannot be deleted'); } @@ -188,9 +189,9 @@ You can stop any event by calling the `cancel(message, [code])` method. You can pass an integer to the `cancel()` method as the second parameter to set the HTTP status code. For example, 401 means "Unauthorized". - //On Put + //On PUT if (this.creator !== me._id) { - cancel("You cannot view this post because it is not yours!", 401); + cancel("You cannot edit this post because it is not yours!", 401); } PUT /posts/13456 @@ -199,7 +200,7 @@ You can pass an integer to the `cancel()` method as the second parameter to set 401 Unauthorized { - "message": "You cannot view this post because it is not yours!" + "message": "You cannot edit this post because it is not yours!" } @@ -207,7 +208,7 @@ You can pass an integer to the `cancel()` method as the second parameter to set Use the `error(name, message)` function to add a validation error. - //On Post + //On Validate if (this.age < 18) { error('age', 'must be older than 18') } @@ -238,7 +239,7 @@ If you wish to hide certain properties from a user, use the `hide(propertyName)` ## Protecting properties from modification -Use the `protect(propertyName)` function to protect specified properties during a POST or PUT. +Use the `protect(propertyName)` function to protect specified properties during a PUT. //On Put protect('createdDate'); \ No newline at end of file diff --git a/docs/files.markdown b/docs/files.markdown index 16a901c..6427935 100644 --- a/docs/files.markdown +++ b/docs/files.markdown @@ -1,19 +1,17 @@ # Files Resource -The Files Resource allows you host static files from your app, such as HTML, browser JavaScript, CSS, images, and videos. +The Files Resource allows you host static files from your app, such as HTML, browser JavaScript, CSS, images, and videos. + +The Files Resource is always included in your app. ## Accessing files Send a GET request with the filename to load the raw file. This is how browsers request pages and files by default. - GET /files/bg.jpg + GET /register.html -## Folders - -If you prefer to have separate folders for Javascript, CSS, and images, create multiple Static Resources at the paths you want to store the files. - -You can also give a Static Resource an empty path `/`. This will assign it to the root of your app. + GET /images/bg.jpg ## Home page -If a Static Resource receives a request without a filename, it will automatically redirect to "index.html" if available. \ No newline at end of file +If the Files Resource receives a request without a filename, it will automatically redirect to "index.html" if available. \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 358c6cb..5bd4fa1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -85,8 +85,7 @@

Deployd is configured so that you can easily develop a web app locally on your computer. It will send Access-Control-Allow-Origin HTTP headers if a request is coming from localhost or your filesystem, which will allow modern web browsers to use AJAX normally. It will not send these headers for any other domain.

-
-

Collection Resource

+

Collection Resource

A Collection resource allows client apps to save and query data.

@@ -94,7 +93,7 @@

After creating a Collection resource in the dashboard, you can set up the schema that will automatically validate data sent to the resource url over HTTP. You can configure this schema in the dashboard.

-

The grid view below the property list allows you to edit the Collection manually.

+

The Data view in the dashboard allows you to edit the Collection manually.

Property types

@@ -177,14 +176,12 @@ Content-Type: application/json

Updating an object

-

A PUT (or POST) request at an object's URL will update the object. You must include all properties except for _id.

+

A PUT (or POST) request at an object's URL will update the properties specified on the object.

PUT /people/4f71fc7c2ba744786f000001
 Content-Type: application/json
 {
-  "age": 24,
-  "firstName": "Fred",
-  "lastName": "Smith"
+  "age": 24
 }
 
@@ -242,10 +239,11 @@ Content-Type: application/json

You can attach micro-scripts to events to add logic and validation to your objects. Collections currently support the following events:

Reading and setting properties

@@ -254,18 +252,20 @@ Content-Type: application/json

You can set values on the this object during an On Post or On Put event. These changes will be saved to the database.

-
// On Post:
+
// On POST:
 this.dateCreated = new Date();
 
-// On Put:
+// On Validate:
 this.totalScore = this.level1Points + this.level2Points;
 
+

Note: If you intend for a property to be "automatic" (calculated by the server, and never provided by the client), you will need to mark it as Optional in the dashboard.

+

Accessing the current user

If the request is coming from a logged in User, you can use the "me" object to access their properties.

-
// On Post:
+
// On POST:
 this.creator = me._id;
 
@@ -273,7 +273,7 @@ this.creator = me._id;

You can stop any event by calling the cancel(message, [code]) method.

-
//On Delete:
+
//On DELETE:
 if (this.protected) {
   cancel('This post is protected and cannot be deleted');
 }
@@ -288,9 +288,9 @@ DELETE /posts/123456
 
 

You can pass an integer to the cancel() method as the second parameter to set the HTTP status code. For example, 401 means "Unauthorized".

-
//On Put
+
//On PUT
 if (this.creator !== me._id) {
-  cancel("You cannot view this post because it is not yours!", 401);
+  cancel("You cannot edit this post because it is not yours!", 401);
 }
 
 PUT /posts/13456
@@ -299,7 +299,7 @@ Content-Type: application/json
 
 401 Unauthorized
 {
-  "message": "You cannot view this post because it is not yours!"
+  "message": "You cannot edit this post because it is not yours!"
 }
 
@@ -307,7 +307,7 @@ Content-Type: application/json

Use the error(name, message) function to add a validation error.

-
//On Post
+
//On Validate
 if (this.age < 18) {
   error('age', 'must be older than 18')
 }
@@ -340,32 +340,28 @@ if (this.creator !== me._id) {
 
 

Protecting properties from modification

-

Use the protect(propertyName) function to protect specified properties during a POST or PUT.

+

Use the protect(propertyName) function to protect specified properties during a PUT.

//On Put
 protect('createdDate');
-
-

Files Resource

+

Files Resource

-

The Files Resource allows you host static files from your app, such as HTML, browser JavaScript, CSS, images, and videos.

+

The Files Resource allows you host static files from your app, such as HTML, browser JavaScript, CSS, images, and videos.

+ +

The Files Resource is always included in your app.

Accessing files

Send a GET request with the filename to load the raw file. This is how browsers request pages and files by default.

-
GET /files/bg.jpg
+
GET /register.html
+
+GET /images/bg.jpg
 
-

Folders

- -

If you prefer to have separate folders for Javascript, CSS, and images, create multiple Static Resources at the paths you want to store the files.

- -

You can also give a Static Resource an empty path /. This will assign it to the root of your app.

-

Home page

-

If a Static Resource receives a request without a filename, it will automatically redirect to "index.html" if available.

-

User Collection Resource

+

If the Files Resource receives a request without a filename, it will automatically redirect to "index.html" if available.


User Collection Resource

A User Collection resource behaves much like the standard Collection resource, but adds the ability to authenticate with a username and password.

@@ -428,8 +424,7 @@ Content-Type: application/json

To logout a user send a POST request to /<collection name>/logout:

204 No Content
-
- +