Sunday, February 24, 2013

Please RTFM

Got my fair share of RTFM last week. I've written a REST-adhering AngularJS code for deletions. I'd written it this way:

$http.delete('/departments', { Id: d.DepartmentId }).success(function (responseData) {

But the record is not deleted.

I assumed the second parameter is a data parameter, I should thought early that second parameter has many options. Another lesson learned, aside from not reading the AngularJS doc, handling errors should be our second nature, the errors provided by ServiceStack helps a lot for debugging why the particular method for RESTful deletion is not routed to its proper service method.

Upon adding .error callback, lot of guessworks were avoided on why there's a 405 error, which naturally led me to read AngularJS doc. $http delete has a config parameter, the second parameter is not directly a data paramater

To correctly pass the data parameter with AngularJS:

$http.delete('/departments', { params : { Id: d.DepartmentId } }).success(function (responseData) {
}).error(function(data, status, headers, config) {

Obligatory xkcd reference:

No comments:

Post a Comment