Friday, June 23, 2017

Fire and forget with Angular 2 REST service calls.

Consider this:

this.http.put(myUrl, myJson, myOptions);

 
 

It does nothing. It fails silently. You have to chain stuff off of the put to get it to do something like so:

this.http.put(myUrl, myJson, myOptions).toPromise().then(function(){},
      function(){}).catch(function(){});

 
 

That's terrible too because, per Roy Fielding, PUT as a verb should not roundtrip something back up to you. At your ASP.NET Web API endpoint you should just have a void method and not a method that returns a true value bool as a hack to accomodate Angular 2. The fix is this:

this.http.put(myUrl, myJson, myOptions).toPromise();

 
 

This was allow you to hit an endpoint that returns void.

No comments:

Post a Comment