Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mgonto/restangular
Browse files Browse the repository at this point in the history
* 'master' of github.com:mgonto/restangular:
  change in README file
  url modified for 'Chain methods together to easily build complex requests'
  Update README.md
  Update README.md
  • Loading branch information
mgonto committed Apr 3, 2015
2 parents e795cd3 + 6b6da70 commit 77a45b9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions README.md
Expand Up @@ -125,7 +125,7 @@ $scope.user.sendMessage(); // POST: /users/123/sendMessage

// Chain methods together to easily build complex requests
$scope.user.one('messages', 123).one('from', 123).getList('unread');
// GET: /user/123/messages/123/from/123/unread
// GET: /users/123/messages/123/from/123/unread


````
Expand Down Expand Up @@ -706,7 +706,7 @@ These are the methods that can be called on the Restangular object.
* **all(route)**: This will create a new Restangular object that is just a pointer to a list of elements for the specified path.
* **oneUrl(route, url)**: This will create a new Restangular object that is just a pointer to one element with the specified URL.
* **allUrl(route, url)**: This creates a Restangular object that is just a pointer to a list at the specified URL.
* **copy(fromElement)**: This will create a copy of the from element so that we can modified the copied one.
* **copy(fromElement)**: This will create a copy of the from element so that we can modify the copied one.
* **restangularizeElement(parent, element, route, queryParams)**: Restangularizes a new element
* **restangularizeCollection(parent, element, route, queryParams)**: Restangularizes a new collection

Expand Down Expand Up @@ -1157,9 +1157,19 @@ RestangularProvider.configuration.getIdFromElem = function(elem) {
return elem[_.initial(elem.route).join('') + "ID"];
}
````

With that, you'd get what you need :)

#### **How can I send files in my request using Restangular?**

This can be done using the customPOST / customPUT method. Look at the following example:
````js
Restangular.all('users')
.withHttpConfig({transformRequest: angular.identity})
.customPOST(formData, undefined, undefined,
{ 'Content-Type': undefined });
````
This basically tells the request to use the *Content-Type: multipart/form-data* as the header. Also *formData* is the body of the request, be sure to add all the params here, including the File you want to send of course. There is an issue already closed but with a lot of information from other users and @mgonto as well: [GitHub - Restangular](https://github.com/mgonto/restangular/issues/420)

#### **How do I handle CRUD operations in a List returned by Restangular?**

The best option for doing CRUD operations with a list, is to actually use the "real" list, and not the promise. It makes it easy to interact with it.
Expand Down

0 comments on commit 77a45b9

Please sign in to comment.