How do I go about converting this to a POST call where I send a specific task id to retrieve all details about that task?
Actually, if you would like to retrieve specific task with all its details, GET request would be more suitable than POST.
In RESTful application GET is supposed to just read elements (with no user-modifications). POST/PUT is reserved for create or update the element, read relevant topic:
PUT vs POST in REST
So in your case, this will get all your tasks, and assign them to $scope.tasks
model:
Restangular.all('tasks').getList().then(function(response) {
$scope.tasks= result;
});
Above getList()
method will make GET request at URL: http://yourdomain.com/tasks
You can also use different notation to achieve the same (check Restangular
documentation for details):
$scope.tasks = Restangular.all('tasks').getList().$object;
or you can assign Restangular object to the Task
variable, which is just a container, holding all valuable Restangular methods and routing. Then you can call various methods on that object:
var Tasks = Restangular.all('tasks');
$scope.tasks = Tasks.getList().$object;
After that you can access specific task in the tasks
collection, and then call some other methods on it:
var MyTask = $scope.tasks[0];
MyTask.get() // this will do GET at URL http://yourdomain.com/tasks/123, assuming 123 is id of existing task
MyTask.post() // this will do POST at above URL
MyTask.put() // this will do POST at above URL
MyTask.save() // this will do PUT or POST - depends if MyTask is going to be udpated or created.
You can also query for specific task manually at URL http://yourdomain.com/tasks/123
:
Tasks.one('tasks', 123).get().then(function(response) {
$scope.mytask = response
});