Using REST in NAnt with a custom HTTP Task
I needed to make HTTP requests to a REST web service from a NAnt script today so I knocked up a custom task. The
HttpClient class from the WCF REST Starter Kit that I blogged about previously came in handy to offload most of the heavy lifting, leaving me to worry about the task related implementation details. The task supports all the HTTP methods and allows you to specify the content type and the content itself. You can also retrieve the response content and status code through properties set by the task. This was all achieved with surprisingly little code.
Bugs in the bit.ly REST API
bit.ly is one of the many websites that offer URL shortening services. It’s certainly one of the better services and integrates nicely with Twitter. I decided to take a look at their REST API but quickly found problems with the expand service, including an obvious bug when results are returned as XML instead of JSON. All of the services allow you to specify JSON or XML as the format for the response. The default response format is JSON.
Introduction to the HttpClient
The WCF REST Starter Kit Preview 2 includes a set of classes designed to simplify interaction with REST web services. The communications are performed using the
HttpClient class with the help of other types from the
Microsoft.Http namespace. These types can be found in the
Microsoft.Http.dll assembly located in the
Assemblies folder of the starter kit.