Click here to Skip to main content
Click here to Skip to main content

How to Retrieve a Scalar Value from a REST method

, 16 Jan 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

B. Clay Shannon
Founder "Across Time & Space"
United States United States
Ideaman and Coder at Across Time & Space, creator of the Windows Store App "Photrax", which can be downloaded as a trial (7 days) from http://apps.microsoft.com/windows/en-us/app/photrax/75c18e6c-96bd-4607-ac43-531aab098ab4
 
Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.
 
I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction: http://www.lulu.com/spotlight/blackbirdcraven
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 16 Jan 2014
Article Copyright 2014 by B. Clay Shannon
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid