自定义方法
- customGET(path, [params, headers]): Does a GET to the specific path. Optionally you can set params and headers.
- customGETLIST(path, [params, headers]): Does a GET to the specific path. In this case, you expect to get an array, not a single element. Optionally you can set params and headers.
- customDELETE(path, [params, headers]): Does a DELETE to the specific path. Optionally you can set params and headers.
- customPOST([elem, path, params, headers]): Does a POST to the specific path. Optionally you can set params and headers and elem. Elem is the element to post. If it's not set, it's assumed that it's the element itself from which you're calling this function.
- customPUT([elem, path, params, headers]): Does a PUT to the specific path. Optionally you can set params and headers and elem. Elem is the element to post. If it's not set, it's assumed that it's the element itself from which you're calling this function.
- customOperation(operation, path, [params, headers, elem]): This does a custom operation to the path that we specify. This method is actually used from all the others in this subsection. Operation can be one of: get, post, put, delete, head, options, patch, trace
- addRestangularMethod(name, operation, [path, params, headers, elem]): This will add a new restangular method to this object with the name
name
to the operation and path specified (or current path otherwise). There's a section on how to do this later.
Let's see an example of this:
// GET /accounts/123/messages
Restangular.one("accounts", 123).customGET("messages")
// GET /accounts/messages?param=param2
Restangular.all("accounts").customGET("messages", {param: "param2"})
All custom methods have an alias where you replace custom
by do
. For example, customGET
is equal to doGET
. Just pick whatever syntax you prefer.