diff --git a/README.md b/README.md
index 0b0cde1..2c9e395 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,18 @@ Attributes
`url="/users/:userId?q={{searchText}}"`
+ Default URLS:
+
+ Method | HTTP method | URL
+ ------------- | ----------- | ---
+ index | GET | /users
+ show | GET | /users/1
+ new | GET | /users/new
+ create | POST | /users
+ update | PUT | /users
+ delete | DELETE | /users/1
+ member foo | PUT | /users/1/foo
+
* **params**
- *type:* hash
@@ -40,6 +52,12 @@ Attributes
Use this URL instead of the default one for "GET /resources/:id" requests.
+ * **newUrl**
+
+ - *type:* string
+
+ Use this URL instead of the default one for "GET /resources/:id" requests.
+
* **createUrl**
- *type:* string
@@ -71,3 +89,40 @@ Events
* **grapp-authentication-error**
Is fired when a REST API call returns a 401 error.
+
+
+Resource Object methods
+-----------------------
+
+ * **index(successCallback, errorCallback)**
+
+ Performs a HTTP GET on the index URL and returns the response data.
+
+ * **show(id, successCallback, errorCallback)**
+
+ Performs a HTTP GET on the show URL with the specified resource id and returns the response
+ data.
+
+ * **new(successCallback, errorCallback)**
+
+ Performs a HTTP GET on the new URL and returns the response data.
+
+ * **create(data, successCallback, errorCallback)**
+
+ Performs a HTTP POST on the create URL with the specified resource data and returns
+ the response data.
+
+ * **update(id, data, successCallback, errorCallback)**
+
+ Performs a HTTP PUT on the update URL with the specified resource id and data and returns
+ the response data.
+
+ * **delete(id, successCallback, errorCallback)**
+
+ Performs a HTTP DELETE on the delete URL with the specified resource id and returns the response
+ data.
+
+ * **memberAction(id, action, successCallback, errorCallback)**
+
+ Performs a HTTP PUT on the member URL with "/action" appended to it and the specified resource
+ id and returns the response data.
diff --git a/grapp-rest-resource.html b/grapp-rest-resource.html
index e1070cd..9616082 100644
--- a/grapp-rest-resource.html
+++ b/grapp-rest-resource.html
@@ -12,7 +12,7 @@
+ attributes="url params resource indexUrl showUrl newUrl createUrl updateUrl deleteUrl memberUrl">
@@ -96,14 +96,12 @@
}
});
},
- update: function(id, data, success, error) {
+ "new": function(success, error) {
return self.$.xhr.request({
- method: 'PUT',
- url: prepareUrl(self.updateUrl || self.url, self.params, id),
+ url: prepareUrl(self.newUrl || self.url, self.params, null, 'new'),
headers: {
'Accept': 'application/json'
},
- body: JSON.stringify(data),
callback: function(data, response) {
var json;
json = (data.trim() !== '' ? JSON.parse(data) : {});
@@ -140,6 +138,28 @@
}
});
},
+ update: function(id, data, success, error) {
+ return self.$.xhr.request({
+ method: 'PUT',
+ url: prepareUrl(self.updateUrl || self.url, self.params, id),
+ headers: {
+ 'Accept': 'application/json'
+ },
+ body: JSON.stringify(data),
+ callback: function(data, response) {
+ var json;
+ json = (data.trim() !== '' ? JSON.parse(data) : {});
+ switch (response.status) {
+ case 200:
+ return typeof success === "function" ? success(json) : void 0;
+ case 401:
+ return self.fire('grapp-authentication-error');
+ default:
+ return typeof error === "function" ? error(json) : void 0;
+ }
+ }
+ });
+ },
"delete": function(id, success, error) {
return self.$.xhr.request({
method: 'DELETE',
diff --git a/src/grapp-rest-resource.coffee b/src/grapp-rest-resource.coffee
index 9f96c47..1029fb0 100644
--- a/src/grapp-rest-resource.coffee
+++ b/src/grapp-rest-resource.coffee
@@ -41,12 +41,10 @@ Polymer 'grapp-rest-resource',
else
error? json
- update: (id, data, success, error) ->
+ new: (success, error) ->
self.$.xhr.request
- method: 'PUT'
- url: prepareUrl self.updateUrl || self.url, self.params, id
+ url: prepareUrl self.newUrl || self.url, self.params, null, 'new'
headers: {'Accept': 'application/json'}
- body: JSON.stringify data
callback: (data, response) ->
json = (if data.trim() != '' then JSON.parse data else {})
switch response.status
@@ -69,6 +67,20 @@ Polymer 'grapp-rest-resource',
else
error? json
+ update: (id, data, success, error) ->
+ self.$.xhr.request
+ method: 'PUT'
+ url: prepareUrl self.updateUrl || self.url, self.params, id
+ headers: {'Accept': 'application/json'}
+ body: JSON.stringify data
+ callback: (data, response) ->
+ json = (if data.trim() != '' then JSON.parse data else {})
+ switch response.status
+ when 200 then success? json
+ when 401 then self.fire 'grapp-authentication-error'
+ else
+ error? json
+
delete: (id, success, error) ->
self.$.xhr.request
method: 'DELETE'
diff --git a/src/grapp-rest-resource.html b/src/grapp-rest-resource.html
index cc52641..f681367 100644
--- a/src/grapp-rest-resource.html
+++ b/src/grapp-rest-resource.html
@@ -10,7 +10,7 @@
+ attributes="url params resource indexUrl showUrl newUrl createUrl updateUrl deleteUrl memberUrl">