Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we determine whether we are using Web API 1 or Web API 2?

Introduce the problem

I would like to know whether we are using Web API 1 or 2. My own packages.config indicates version 5.0.0. Is that Web API 1 or 2?

Search, and research

I have tried Googling the following:

"web api 1" "web api 2"

and

ASP.NET Web API release history

and

ASP.NET Web API nuget

The best references seem to be these two nuget pages:

  • ASP.NET Web API Nuget seems to indicate that anything 4.* is Web API 1,
  • Microsoft ASP.NET Web API 2.1 Nuget that anything 5.* is Web API 2.

Is that right? How would I know for sure?

like image 669
Shaun Luttin Avatar asked May 06 '14 18:05

Shaun Luttin


People also ask

How do I know what version of Web API I have?

To check this, you can open your solution, expand the webapi solution, then open the packages. config file that holds the nuget config for what you have installed. You should see some web api version message in the below.

What is the difference between Web API and Web API 2?

Actually WebAPI 2.0 is enhanced feature of WebApi there is no difference between this two. In version 2.0, the Web API framework has been enhanced to support the following features: IHttpActionResult return type. A new Routing Attribute.

What is a Web API 2?

In its simplest form, a Web API is an API over the web (HTTP). ASP.NET Web API is a framework that allows you to build Web API's, i.e. HTTP-based services on top of the . NET Framework using a convention based and similar programming model, as that of ASP.NET MVC.


3 Answers

I think what you found seems correct. I had the same question then I had a look under my installed packages when you go "Manage Nuget packages". There was an item installed with the name "Microsoft ASP.NET WEB API 2.2". So I was able to determine my own version from there.

like image 157
John Avatar answered Oct 18 '22 22:10

John


I'm not sure what @John meant with the package name above. I'm having the following package right now:

Microsoft.AspNet.WebApi.5.2.3

Based on this article http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-22 I assume that starting from the package version 5.2.2 it's Web API 2.2 version.

like image 35
SerjG Avatar answered Oct 18 '22 22:10

SerjG


I always try this instead -

In the controller make a method

public IHttpActionResult MyResult(){
    return Ok();
}

If you get compilation error then it is API 1.0.

If no compilation error then you are referencing API 2.0.

like image 15
Newton Sheikh Avatar answered Oct 19 '22 00:10

Newton Sheikh