Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the difference between Web API and REST API in MVC?

I have a little understanding on REST API. As per my knowledge it is used to work with HTTP services (GET, POST, PUT, DELETE).

When I add a Web API controller it provides me some basic methods like :

 public class Default1Controller : ApiController     {         // GET api/default1         public IEnumerable<string> Get()         {             return new string[] { "value1", "value2" };         }          // GET api/default1/5         public string Get(int id)         {             return "value";         }          // POST api/default1         public void Post([FromBody]string value)         {         }          // PUT api/default1/5         public void Put(int id, [FromBody]string value)         {         }          // DELETE api/default1/5         public void Delete(int id)         {         }     } 

So my question is: what's the difference between a Web API and a REST API?

By the definition of REST, the above code is REST based so what's a normal Web API in MVC? I'm a bit confused as some people say you use a Web API with REST?

Kindly provide a better understanding of them both.

like image 481
rohit singh Avatar asked Feb 24 '15 18:02

rohit singh


People also ask

What is the difference between a Web API and a REST API?

Web API can be hosted only on an Internet Information Service (IIS) or self that supports XML and JSON requests. In contrast, REST API can be hosted only on IIS that supports standardized XML requests.

What is the difference between MVC and REST API?

MVC is about how the inner side of your app works. REST is about how your app "talks" with other apps. You can combine them. MVC is a design pattern for creating a separation of concerns and avoiding tightly coupled data, business, and presentation logic.

Why We Use Web API instead of MVC?

1. 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. 2. Web API helps to build REST-ful services over the .

Can we use Web API with MVC?

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the . NET Framework.


1 Answers

I have been there, like so many of us. There are so many confusing words like Web API, REST, RESTful, HTTP, SOAP, WCF, Web Services... and many more around this topic. But I am going to give brief explanation of only those which you have asked.

REST

It is neither an API nor a framework. It is just an architectural concept. You can find more details here or tutorials here https://restfulapi.net/

RESTful

I have not come across any formal definition of RESTful anywhere. I believe it is just another buzzword for APIs to say if they comply with REST specifications.

EDIT: There is another trending open source initiative OpenAPI Specification (OAS) (formerly known as Swagger) to standardise REST APIs.

Web API

It in an open source framework for writing HTTP APIs. These APIs can be RESTful or not. Most HTTP APIs we write are not RESTful. This framework implements HTTP protocol specification and hence you hear terms like URIs, request/response headers, caching, versioning, various content types(formats).

Note: I have not used the term Web Services deliberately because it is a confusing term to use. Some people use this as a generic concept, I preferred to call them HTTP APIs. There is an actual framework named 'Web Services' by Microsoft like Web API. However it implements another protocol called SOAP.

like image 99
Rajiv Avatar answered Sep 29 '22 01:09

Rajiv