REST web services are pretty straightforward and really, really common (you used one to read this blog page). As software gets implemented as services, it’s getting more and more common for us as developers to have to make REST calls programmatically. Lately I’ve been implementing a lot of services using Padarn on both the device and the PC and then implementing client libraries to access those services. In doing so, it only made sense to create some infrastructure to make my life a little easier, and so the RestConnector (and DigestRestConnector) was born.
For a simple GET, such as to get the response for this page, the code is trivial:
var connector = new RestConnector(“blog.opennetcf.com”);
var response = connector.Get(“/ctacke”);
Other verbs like POST and PUT are nearly as simple.
var response = connector.Post(“/upload”, myData);
For services that require authentication, there’s the DigestRestConnector that behaves the same, except the ctor takes in a UID/PWD pair as well. The classes support the four common verbs I use: GET, PUT, POST and DELETE. Of course since it’s open-source, feel free to extend them as you wish.
The OpenNETCF Extensions library is a collection of extension methods and helper classes that I find useful in a lot of different projects. It’s compatible with the Compact Framework, Tirethe full framework and Windows Phone.