Disclaimer: This is a user generated content for MyStory, a YourStory initiative to enable its community to contribute and have their voices heard. The views and writings here reflect that of the author and not of YourStory.

How to create a web API with ASP.NET

Web API Using ASP.NET
0 CLAPS
0

What is Web API?

A web API is an Application programming language that is used to generate a communication between software components. ASP.NET is a framework that makes easy to build and reaches a wide range of clients, including browser and mobile devices. Through ASP. NET, web API can enable interaction of different devices from the same database.

Diagram


Diagram

How Web API works?

• Web API is used to access the service data, many mobile applications and the other devices.

• It helps to create Restful (Representational State Transfer) web services.

• IT used to create an HTTP web services that supports XML, JSON and other data formats.

• Initially, it is used to build web services which are lightweight, scalable and conceivable.

Steps for creating web API

1. We will start with the Visual studio. Open visual studio and open new project. Select Menu >> Web >> ASP.NET web application. Give project name and click OK


2. After opening the template window, select WEB API, Some messages will appeared at the right side. Now, click on OK button.


3. Now, our project will open. Go to the controller where we can see “ValueController.cs” This is the main class for Web API. It is created by default.


Create a new controller with a different name. Select Controller >> Add >> Controller as below.Select “Web API Controller – Empty“ and click on “Add” button.

4. Now, create a method in the controller, built the application and run. We will use “get()” method for it. Below is the code.


5. We need to run API URL format. Fer Example, We create Url format in MVC using “ RoutConfig” & “RegidterRoutes” class and static methods. Same as in Web API we will use “ WebApiConfig” & “Register” static methods.


6. Now built a project and run it in above mentioned format. As we have created a Demo controller, it will run it in following URL “http://localhost:53027/api/Demo”

It will give you the output in following manner.


Above article can help new learners, students and fresher about an integration of Web API. To learn more you can visit http://www.concettolabs.com/blog/