.NET offers two alternate ways to access a REST API (including ASP.NET Web API). The typical way to access a REST API is using the HttpClient.

The HttpClient does a POST on the REST API and receives a JSON response. The JavaScriptSerializer is used to parse the JSON response to a custom object.

The alternate way to access a REST client is using WCF. WCF offers webHttpBinding which is used to access any REST client.

Using the WCF client, the REST API can be invoked using an interface method. The interface is added to the client project based on the request parameters in the URL.

The UriTemplate of the WebInvoke attribute is used to convert the method parameters to the query string in the request URL.

Whenever possible, the WCF client is preferred. Using WCF client, the REST API is accessed using interface methods. This makes the code more testable.

Alternate ways to invoke a REST API
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *