
Many of you have seen applications for Amazon, E-bay, etc. out there for phones. Well many of these connect to the original website through a web service using something many refer to as REST protocol..
Connecting to these services aren’t difficult but authorizing the application and the user and getting access to features and data provided isn’t always easy.. It can be long and convoluted and take time and extra code making your application bigger than needed be. Luckily most websites that offer access to mobile applications and other websites offer a standard way to do all of this.. But still even with that you might finding yourself wanting to cut down on that side of the development equation.
ENTER HAMMOCK
Hammock features caching, asynchronous operation, mocking, retry, timeout, and rate limiting support, Hammock is a complete RESTful communication library for .NET.
Features
- Simple, clean API for consuming RESTful services in .NET
- Sequential and asynchronous operation
- Extensible security with Basic Authorization and OAuth/xAuth support
- Extensible serialization with XmlSerializer, DataContractSerializer, JavaScriptSerializer, and JSON.NET support
- Extensible caching with ASP.NET Cache support
- Retry, timeout, periodic tasks, and rate limiting
- Transparent mocking layer
- Multipart fields and file support
Supported .NET versions (EVERYTHING CURRENT)
.NET 3.5 SP1 .NET 4.0 RC Windows Phone 7 Compact Framework 3.5 SP1 Silverlight 3 and 4 RC Mono 2.6
This cool library is up on Codeplex and is the fantastic work of: Daniel Crenna and Jason Diller..
You can download this at:
http://hammock.codeplex.com/
Here’s an example of how easy to work with this is.. only a few lines and you have twitter access..
IWebCredentials credentials = new BasicAuthCredentials
{
Username = "username",
Password = "password"
};
RestClient client = new RestClient
{
Authority = "http://api.twitter.com",
VersionPath = "1"
};
client.AddHeader("User-Agent", "Hammock");
RestRequest request = new RestRequest
{
Credentials = credentials,
Path = "statuses/home_timeline.json"
};
request.AddParameter("count", "20");
RestResponse response = client.Request(request);
if(response.StatusCode == HttpStatusCode.OK)
{
// ...
}