1

I have been asked about the difference between Web API and RESTful services and that is also an interesting question to me. From my point of view, the only possible difference between RESTful service and Web API can be considered as that RESTful services are inherently meant to be stateless (although we can use cookies), while the concept of being inherently stateless does not apply to Web APIs as we can use sessions (can't be used in RESTful service).

However, I decided to post this question to see if there are any other potential differences that distinguish these two technologies from one another.

Arnold Zahrneinder
  • 4,788
  • 10
  • 40
  • 76

2 Answers2

10

You're comparing a programming framework and a design paradigm. That's not a fair comparison.

Web API is a web service application framework. You can implement a REST API using it, but you don't have to. You can also write RPC-style services in it, or really just any kind of application that talks HTTP but doesn't (strictly) adhere to the REST principles.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Yeah that seems right, but do you think that a RESTful interface writing in Web API (as it inherently supports sessions/cookies) does not necessarily have to be stateless? – Arnold Zahrneinder Feb 05 '17 at 10:10
  • [No. As soon as you use state, such as sessions, you don't have a REST service anymore](http://stackoverflow.com/questions/6068113/do-sessions-really-violate-restfulness). – CodeCaster Feb 05 '17 at 10:11
  • Ok, conclusion is that as you said, the design concept must NOT be mixed with the development environment. :) – Arnold Zahrneinder Feb 05 '17 at 10:13
  • 3
    That's it. It's fine that the framework lets you use sessions. Just note that if you use them in a web service, that's technically not a REST service anymore. – CodeCaster Feb 05 '17 at 10:16
4

REST is just an architectural style. It's not any protocol or framework. You can implement RESTful services using many frameworks and programming languages. Web API is just one of them for .NET.

It's true that RESTful services are stateless. Here is the list of main REST constraints:

  • Client-Server
  • Stateless
  • Cache
  • Uniform interface
  • Layered system
  • Code-On-Demand

For more details about REST architecture I recommend Roy Fielding's publications under this link.

Coming back to your doubts, you can implement RESTful service with Web API framework, but only if you follow the rules of REST architectural style.