开发者

How to write REST API wrapper in C#?

开发者 https://www.devze.com 2022-12-18 14:01 出处:网络
An application I u开发者_如何学Gose has a REST API. In C#, is there an example of writing a wrapper for this to invoke the API\'s functions?

An application I u开发者_如何学Gose has a REST API. In C#, is there an example of writing a wrapper for this to invoke the API's functions?

Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消