Reputation: 13823
Are there any .net REST libraries which support Windows Phone 7 and silverlight?
Upvotes: 1
Views: 597
Reputation: 9192
Restful-Silverlight is a library I've created to help with both Silverlight and WP7.
True, you can just use HttpWebRequest and HttpWebResponse, but this library will help you deal with the asynchronous nature of Silverlight. You use a class called AsyncDelegation to orchestrate what you want to do asynchronously. I have included code below to show how you can use the library to retrieve tweets from Twitter.
Sample Usage of Restful-Silverlight retrieving tweets from Twitter:
//silverlight 4 usage
List<string> tweets = new List<string>();
var baseUri = "http://search.twitter.com/";
//new up asyncdelegation
var restFacilitator = new RestFacilitator();
var restService = new RestService(restFacilitator, baseUri);
var asyncDelegation = new AsyncDelegation(restFacilitator, restService, baseUri);
//tell async delegation to perform an HTTP/GET against a URI and return a dynamic type
asyncDelegation.Get<dynamic>(new { url = "search.json", q = "#haiku" })
//when the HTTP/GET is performed, execute the following lambda against the result set.
.WhenFinished(
result =>
{
textBlockTweets.Text = "";
//the json object returned by twitter contains a enumerable collection called results
tweets = (result.results as IEnumerable).Select(s => s.text as string).ToList();
foreach (string tweet in tweets)
{
textBlockTweets.Text +=
HttpUtility.HtmlDecode(tweet) +
Environment.NewLine +
Environment.NewLine;
}
});
asyncDelegation.Go();
//wp7 usage
var baseUri = "http://search.twitter.com/";
var restFacilitator = new RestFacilitator();
var restService = new RestService(restFacilitator, baseUri);
var asyncDelegation = new AsyncDelegation(restFacilitator, restService, baseUri);
asyncDelegation.Get<Dictionary<string, object>>(new { url = "search.json", q = "#haiku" })
.WhenFinished(
result =>
{
List<string> tweets = new List();
textBlockTweets.Text = "";
foreach (var tweetObject in result["results"].ToDictionaryArray())
{
textBlockTweets.Text +=
HttpUtility.HtmlDecode(tweetObject["text"].ToString()) +
Environment.NewLine +
Environment.NewLine;
}
});
asyncDelegation.Go();
Upvotes: 0
Reputation: 10609
I've had a lot of success using Hammock especially when requiring something like OAuth.
Upvotes: 1
Reputation: 67178
What, exactly, do you mean? Do you mean a library "helper" that can wrap up REST calls for you like RestSharp (which supports Windows Phone)?
Or do you mean something that allows the device to serve REST services (not going to happen since V1 doesn't support sockets, among other reasons)?
Or do you mean something altogether different?
Upvotes: 1
Reputation: 700382
You don't need a library. REST is just based on the original intentions with the HTTP protocol, and that's supported by the classes in the .NET framework.
You can use the HttpWebRequest
or WebClient
classes to make requests.
Upvotes: 0