Hi Folks, today i will share about how to consume REST Web Based API in .NET. This post will resume the entire way to consume REST API from Web, Desktop, and Xamarin. Let's get started.
Why the REST web API important?
Because the REST based API replaces the previous techhnology such as Web Services, Remoting, and common TCP/IP communication. the simplification of the REST gives developer more time to work with the business process rather than work for improving the communication between system. This post won't discuss about how to design the REST API but how to consume it. If you want to learn about the design principles please go here . Nowadays, many software communicate each other with Rest web Based API. For example, Twitter, Microsoft Graph, Facebook, and many more. This post become fundamental for developer who want to consume the API for their application
Considering the Access
In general, you have two ways to consume REST based API. Parsing or Wrapping. Parsing is done by understanding the XML or JSON request and then read the response by using interpreter of JSON or XML. A good example of parsing method is Graph Explorer. You can see the example here http://dapalan.com/LdFh. Wrapping is using ready to use API that help specific developer to acomplish the mission. For example, is Graph API SDK
When to use parsing method
- You want to reuse the code in similar environment such as consuming console app, desktop app, and UWP app all together without considering the different SDK
- You want faster and smoother experience when the API changes. The drawback of the Wrapping method is depend with the supported API, so when the API changes you should reconfigure the wrapper
//
When to use wrapping method
- you dont understand how to parse, split, and read JSON or XML syntax and operation
- you need faster way to develop the solution without thinking the detail
Consuming Strategy
Option A. Using Generic Way (Parsing)
I recommend you to learn by using Newtonsoft JSON. They have 100 codes sample to help you to understand how to serialize and de-serialize API that use JSON
Option B. Using Specific API (Wrapping)
This is recommended way, if your codes is supported by the API maker. For example Graph Explorer SDK, and others.
In the next post we will show you some sample codes to do that.
//