Consuming Rest API in an Easy Way

Background There are numerous ways to consume REST API in C#. Starting with HttpClient, WebClient, HTTPWebRequest and Third-Party API. On this post, I will show you how to consume REST API in an easy way with C#. Requirements For this lab we use: Visual Studio 2019 – http://visualstudio.com Newton soft JSON - https://www.newtonsoft.com/json/ Rest sharp - http://restsharp.org/ Horoscope REST API sample – http://sandipbgt.com/theastrologer/api/horoscope // Let's get started #1 Creating a project with Visual Studio 2019 we created two projects the first one is Class Library and the second one is Console App. It used .NET Framework 4.7.2. we downloaded two Nuget package: Newtonsoft JSON and RestSharp for the Class Library project #2 Composing Classes for our REST objects The REST API will be consumed as an object. Therefore, we created several classes and enumeration #3 Creating Class that Consumes the REST API We created a class that has a method to consume REST API. We deserialize the REST API as shown below. We read the content and save the result into Zodiacresult Class. Please note we use DeserializeObject (from newtonsoft) and RestClient (from restsharp). #4 Creating Class that Display the REST API We created a console app that consume the library. The REST API has a nested result. Therefore, the Zodiacresult contains an array namely Meta object. We consume the Meta object and accessing through their properties. #5 Testing the result Lets push the F5 button and you can see, we can consume the rest API easily in dotnet. Have a question? Just put it in the comments. Enjoy your weekend. //

Integration technology in the cloud

Regardless of the organization's need to make a profit. There is always a need for partnerships to improve existing businesses, partnerships are carried out through market development, bundling business collaboration, and technology integration. In this post, we will discuss how technology integration is part of the key to the success of industry 4.0. Today's technology integration has at least three characteristics. The first characteristic is to follow standards. Integration standards will encourage how one business with other businesses greet and collaborate with each other. The second karasteristic is the common development technology. Organizations on the basis of developing microservices for example will be easier to coordinate with other organizations that have similarities. The third characteristic is the alignment of business processes. For example, logistics business processes are very close to sales business processes. The two business processes will be very likely to be integrated because businesses support each other. Then what technologies are commonly used for integration. Following are three development models that encourage integration. Web services. Web services. this old technology is still combined with newer technology. For example, SOAP-based web services are still used for compatibility. The xml-based web services are now starting to use simple protocols such as REST. The REST protocol that is quite simple is now widely used with a simpler data format than XML, namely JSON. Microservices. Unlike the high level API SOA. Microservice emphasizes a low level API approach. In other words, for a simple process there are interfaces that can be used separately in a process. For example, if SOA is discussing credit card payment validation, microservices provides an API to validate details idenetification of the master card / visa / amx card. low codes integration. this approach is widely used by business users who want to do a technology orchestra. like wanting to post social media to Twitter when a post on Instagram exceeds 100 likes. This system is widely available in the market for digital marketing needs to business automation. Examples of this technology such as Microsoft Flow. // Thus, the three technologies that characterize integration in the modern era. Has something been missed? let's share here  

How to consume REST Based API

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.   //

Topics Highlights

Translate It

About @ridife

This blog will be dedicated to integrate a knowledge between academic and industry need in Application Lifecycle Management (ALM), ICT tips, and Software Engineering Research. Enjoy this blog and let's get in touch in any social media.

Xbox

Month List