Correct and that is how I am currently doing it. However, it would
make sense to be able to have it throw exceptions to allow catching of
them with a try/catch to handle proper RESTful controller actions in
MVC.
Currently I have to do the following to have my code react to
statuscodes:
var client = new RestClient();
var request = new RestRequest();
var response = client.Execute(request);
// Handle expected status codes properly
switch (response.StatusCode)
{
case HttpStatusCode.OK:
// reaction to HttpStatusCode
case HttpStatusCode.NotFound:
// reaction to HttpStatusCode
case HttpStatusCode.Forbidden:
// reaction to HttpStatusCode
default:
// reaction to HttpStatusCode
}
The other idea would be to subscribe events based on the statuscode at
the end of the request and handle each of those events as seen fit.
this would allow for better SRM objects and handling of RESTful
service calls. This would result in this API pattern:
var client = new RestClient();
var request = new RestRequest();
// Assign events on request to be handled appropriately
request.OnForbidden += MyForbiddenHandler;
request.OnNotFound += MyNotFoundHandler;
request.OnSuccess += MySuccessHandler;
// on this execution request/response would evaluate all the events
registered above that were needed
var response = client.Execute(request);