locked
In web api what kind of operation should be Get type and what kind of operation should be post type RRS feed

  • Question

  • User264732274 posted

    i am very new in web api. i have often seen people compose a action with get type verb when action take no argument or when action take normal dotnet data type like int, string, date time etc and when action take complex type like customer or list<customer> then they compose action with post or put type. please tell me why ?

    can we compose a action with get type whose argument will be complex type like customer or list<customer> ?

    i am new and i like to understand this. please discuss in details with example. thanks

    Friday, August 5, 2016 8:41 AM

Answers

  • User36583972 posted

    Hi sudip_inn,

    In web api what kind of operation should be Get type and what kind of operation should be post type

    he ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

    You can refer the following link and get a better understand about http methods. It is better for your build a RESTful service.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

    When we build Web API, you can perform CRUD operations in different HTTP methods according to your needs.

    can we compose a action with get type whose argument will be complex type like customer or list<customer> ?

    You can only send your data from url:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:29679/api/Values?Surname=Testing&FirstName=Testing&OtherNames=Testing&Sex=Male&Address1=50DKD&&Address=lagos&Phone=89979797&ReferenceNumber=596969itit&Statecode=20&UTINType=IND&sevenINT=009999");
                request.Method = "Get";
                request.KeepAlive = true;
                request.ContentLength = 0;
                request.ContentType = "application/json";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string myResponse = "";
                using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    myResponse = sr.ReadToEnd();
                }
    

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 8, 2016 4:41 AM