In my RESTful API I return a redirect (303) in some special cases (e.g. an internal subscription is expired; I know this doesn't sound REST). In order to test my API I wrote a simple webpage using jQuery. However, in case I get a 303 it seems like the browser (XHR?) takes care of the redirect itself and GETs the new resource. As this is hidden from the Ajax call it gets just a 200 at the end. Of course this is misleading as the original call didn't succeed! Obviously this is not what I had in mind: I wanted my client-script to know it has to do something different (-> GET another resource).
Now I'm asking myself whether it's a good idea to even return a 303? Instead I could return a simple 4xx and leave the client on its own.... (probably starting from scratch)
$.ajax({
url: self.links()[0].href,
type: "POST",
statusCode: {
200: function () {
//I always ended up here
},
303: function () {
}
},
complete: function (e, xhr, settings) {
if (e.status === 200) {
//..and then here
} else if (e.status === 303) {
} else {
}
}