60

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.

Vincent McNabb
  • 33,327
  • 7
  • 31
  • 53
rohit singh
  • 1,239
  • 3
  • 15
  • 26

2 Answers2

94

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.

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
Rajiv
  • 1,426
  • 14
  • 21
  • How is a web API a framework? a framework is entirely different thing. It allows us to make things. While an web api is an api that runs on the web and connects two different applications, it's a connecter. How is a connecter, a framework? – Shahzad Rahim May 04 '22 at 05:46
  • @ShahzadRahim it's ASP.NET Web API to be specific, with respect to the technology in question asked. see https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api – Rajiv May 05 '22 at 08:06
16

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.

REST

RESTs sweet spot is when you are exposing a public API over the internet to handle CRUD operations on data. REST is focused on accessing named resources through a single consistent interface.

SOAP

SOAP brings it’s own protocol and focuses on exposing pieces of application logic (not data) as services. SOAP exposes operations. SOAP is focused on accessing named operations, each implement some business logic through different interfaces.

Though SOAP is commonly referred to as “web services” this is a misnomer. SOAP has very little if anything to do with the Web. REST provides true “Web services” based on URIs and HTTP.

Reference: http://spf13.com/post/soap-vs-rest

And finally: What they could be referring to is REST vs. RPC See this: http://encosia.com/rest-vs-rpc-in-asp-net-web-api-who-cares-it-does-both/

Chadembox
  • 177
  • 6
  • 1
    please understand my question. I want the difference w.r.t to a web api controller. – rohit singh Feb 24 '15 at 18:24
  • I think you didn't understand what REST really is. ASP.NET is NOT suited to make *REST* applications. ASP.NET WebAPI is awesome and great to create API's, but the word REST should not be used in that context. You can make REST API's with ASP.NET, but it is difficult and not goal driven (see http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven) – rst Aug 18 '17 at 05:49
  • 1
    This is an amazing answer to the difference between rpc vs resource oriented apis. Soap apis can also be restful – Zach Smith Mar 23 '18 at 09:14