How it works...

In steps 1 to 11, we created an empty solution. Then we added a .NET Standard 2.0 library to that solution. Again, as a good practice we properly named the solution and the class library project. In steps 12 and 13, we changed the name of the default Class1.cs created by Visual Studio. In step 15, we added using directives required for our task. In step 16, we created a class-wide private variable to hold the service URL. Then, in step 16 we created the default constructor with a string parameter that updates the private variable in step 15.

In step 18, we created the public method that did the actual work of reading the RESTful API. In the first line of code, we created a string variable that held the output from the service. Then, we created an instance of the HttpClient class inside a using statement. This is a good practice that will make sure the class is destroyed after we exit the using statement.

Then we populated the Universal Resource Indicator (URI) to the service. After that, we did the actual call to the service and stored it inside a HttpResponseMessage variable. Finally, we got the output from the response and returned the output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.215