Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use WebAPI without ASP.NET MVC?

I would like to use WebAPI for an existing project of mine (classic ASP.NET), but as far as I can tell you can only use WebAPI with MVC.

Is it possible to use WebAPI with ASP.NET?

like image 239
Darcy Avatar asked Apr 24 '12 21:04

Darcy


People also ask

Can we create Web API without MVC?

An API is supposed to provide services without being coupled with its consumer application. There is a common misconception that for developing Web APIs, we have to go by ASP.NET MVC application. In this article, we will develop an independent API which is not coupled with a ASP.NET MVC application type.

What is the difference between ASP.NET MVC and Web API?

Asp.Net MVC is used to create web applications that returns both views and data but Asp.Net Web API is used to create full blown HTTP services with easy and simple way that returns only data not view.


1 Answers

From the linked page:

Although ASP.NET Web API is packaged with ASP.NET MVC, it is easy to add Web API to a traditional ASP.NET Web Forms application. This tutorial walks you through the steps.

To use Web API in a Web Forms application, there are two main steps:

Add a Web API controller that derives from the ApiController class. Add a route table to the Application_Start method. Create a Web Forms Project

Start Visual Studio 2010 and select New Project from the Start page. Or, from the File menu, select New and then Project.

In the Templates pane, select Installed Templates and expand the Visual C# node. Under Visual C#, select Web. In the list of project templates, select ASP.NET Web Application. Enter a name for the project and click OK.

like image 127
Nesim Razon Avatar answered Oct 12 '22 23:10

Nesim Razon