Articles → ASP .NET WEB API → Consume Web API Get Method Using C#

Consume Web API Get Method Using C#






Create Web API




public class TestController: ApiController { 
    public List < string > GetTrafficSignalColor() {
        return new List < string > () {
            "Red",
            "Green",
            "Orange"
        };
    }
}



Create C# Application




using(var client = new WebClient()) { 
    client.Headers["request-type"] = "application/json";
    string result = client.DownloadString("http://localhost:19800/api/Test");
    Console.WriteLine(result);
    Console.ReadLine();
}



Output




Picture showing the output of calling the get method of webapi in C#
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, February 27, 2016

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250