Saturday 9 February 2019

Create The Simple WebAPI Application using C#.net in 7-Steps


Hello Friends,
 Now I am going to describe how to create Simple WebAPI Application in 7-Steps  without DB Connection using C#.net in Visual Studio 2017.After that We will discuss How to call this WebAPI in MVC application and  create WebAPI Application with DB Connection using 3-layer architecture,I hope it'll be  helpful for beginner, Please follow in below steps                                                                                            

Step:1
Open your Visual Studio go to File Menu and create New Project.










Step:2      
Select Asp.Net Web Application(.net Framework), provide Name and select your Location and click on OK button. 












Step:3
Select Empty option from ASP.NET 4.6.1 Templates and select on both Web API  and  MVC option click on OK button.







Step:4
After create the WebAPI Project go to Controller folder from solution Explorer
Right click on Controller -> add->Controller







Step:5
Select  this option: Web API 2 Controller-Empty







Step:6
Provide Name and click on add button.






Step:7
Write this code in the controller Part for display this record in Browser in XML Format
using System.Collections.Generic;
using System.Web.Http;

namespace TestAPI.Controllers
{
    public class WebAPITestController : ApiController
    {
        public static List<string> Myfriend = new List<string> { "Jsendha""Dilu""Biranchi""Susanta""Raghu""Srusti""Santosh" };

        [HttpGet]
        public List<string> GetFriendName()
        {
            return Myfriend;
        }
        [HttpGet]
        public string GetFriendNameByID(int id)
        {
        
            return Myfriend[id];
        }

    }
}
Step:8 
After Run this application, change your URL format (locahost:52634/api/controllername/)









I’ve explained the simple process of WebAPI and  next session we will discuss how to call this WebAPI in MVC application. So after read please Comments and suggestions.
Thanks & Regard
Rabi

No comments:

Post a Comment