Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write REST API wrapper in C#?

Tags:

c#

An application I use has a REST API. In C#, is there an example of writing a wrapper for this to invoke the API's functions?

Thanks

like image 713
blade1 Avatar asked Oct 15 '22 10:10

blade1


1 Answers

Writing your own wrapper for REST usage is not terribly difficult. Any client would be making use of the HttpWebRequest and HttpWebResponse objects to execute GET requests and retrieve the results. (There are other objects in the .Net Framework that can be used, but I've found these to be the most useful.)

This is actually the simple part. How you interpret the results (read as a string, parse the xml response, deserialize to strongly-typed objects, etc.) are more involved in the decision process. My advice to this end: keep it as simple as you can, but make your wrapper self-contained. Don't require your calling logic to have to know anything about sending the request or interpreting the response.

like image 66
jro Avatar answered Oct 21 '22 09:10

jro