Restsharp calling web api - Get Call


Rest sharp Calling web api using restsharp - Get Call


Web api Controller.cs
public class MyApiController : ApiController
    {
        public IHttpActionResult Get() {

            var models = new List<Student>() {
                new Student(){ StudentId=1,Name="Student1"},
                new Student(){ StudentId=2,Name="Student2"},
                new Student(){ StudentId=3,Name="Student3"},
            };
            return Ok(models);
        }
}
        public ActionResult Index()
        {
            var apiUrl = @"http://localhost:8076/api/MyApi";
            var client = new RestClient(apiUrl);
            var request = new RestRequest(Method.GET);
            request.AddHeader("Accept", "application/json");
            var result = client.Execute(request).Content;
            var finalResult = JsonConvert.DeserializeObject<List<Student>>(result);
            return View();
        }

Share on Google Plus

About myzingonline

Myzingonline is all about zing to share experience, knowledge, likes, dislikes and ideas of a person to the world.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment