Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Retrieve a Scalar Value from a REST method

0.00/5 (No votes)
16 Jan 2014 1  
Retrieve scalar vals from REST methods

Easy as Eating Pie and Much Faster

If you are just retrieving a scalar (single) value from a REST method (as opposed to an array of json elements or so), it is easy as eating huckleberry pie to call the method and consume the value it returns. How easy? Czech it out:

private string GetScalarVal(string uri)
{
    var client = new WebClient();
    return client.DownloadString(uri);
}

Now you can call this method as many times as there are methods of that ilk like so:

private void buttonYourLip_Click(object sender, EventArgs e)
{
    MessageBox.Show(GetScalarVal("http://localhost:28642/api/duckbilledPlatypi/Count"));
}

Hats off to Larry, I mean Jon Skeet, for turning me on to WebClient.DownloadString()

As the Frenchmen say, voilĂ !

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here