8

I've tried to read about what RESTful webservices from Wikipedia etc but I must admit I don't get it. There is a film in which Denzell Washington says "explain it to me like I'm a 5 year old". Can someone do that for me regarding RESTful services?

Bonus points if you know the name of the film.

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • 1
    [I just updated this earlier today](http://stackoverflow.com/questions/4573305/rest-api-why-use-put-delete-post-get/4573426#4573426). – zzzzBov Dec 13 '11 at 17:26
  • 1
    Also, [Philadelphia](http://en.wikiquote.org/wiki/Philadelphia_(film)), but it seems you misquoted. – zzzzBov Dec 13 '11 at 17:27
  • there's not much four-year-oldness in that post. In essense what is it and how does it differ from SOAP? A simple example would be great. – Sachin Kainth Dec 13 '11 at 17:32
  • i posted it because it's related, not because it's an answer. – zzzzBov Dec 13 '11 at 17:49
  • 1
    "What is REST?" is a really bad question for this site. Google is a much better place to go to find an answer for broad questions like this. – Nicholas Shanks Dec 05 '12 at 13:09
  • Even I am going through the same problem, but i know the movie. #Philadelhia – vipul_vj Sep 09 '13 at 09:03

2 Answers2

22

When I first started with REST, I too had some difficulty getting the "big picture", despite all the documentation out there. Anyways, here's my brief take on REST:

  • REST is an architectural style for building web services.

  • REST is built on top of HTTP. Your web service exposes Resources in the form of URIs. Your service allows clients to act upon your service using the standard HTTP verbs (GET=read the resource, POST=create the resource, PUT=update the resource, DELETE=delete the resource).

  • REST has gained significant momentum in the past few years due largely to (a) Its simplicity over other styles like SOAP. (b) The ubiquity of HTTP. Because HTTP is a time-tested standard, most languages have build-in or 3rd-party HTTP support. You cannot say the same thing about SOAP.

  • Because REST is a style and not a strict protocol/specification, there is lots of room for interpretation. Many public services that call themselves "REST" do not follow the style to the letter.

EJK
  • 12,332
  • 3
  • 38
  • 55
  • 3
    This answer misses a hugely important part of the REST architecture, called [HATEOAS](http://en.wikipedia.org/wiki/HATEOAS). This affords [loose coupling](http://en.wikipedia.org/wiki/Loose_coupling), and allows the server to change/"evolve" independently of clients. That's way, way more than you can say about SOAP services, and is part of why the web itself was successful. REST is, in fact, an attempt at formalizing the generalized architecture of the web we've already been using, and hypertext/hyperlinking is arguably the most important part of the web, and thus REST. – Merlyn Morgan-Graham Oct 09 '13 at 07:02
5

RESTful services are services that transfer state represntationally, hence the name REpresentational State Transfer. What this actually means is that data is passed in a declarative manner, which is to say, you get what you ask for.

REST is different from SOAP in that it's not a protocol, and there's no formal specification. SOAP was created to simplify data transfer between applications by using a common interface to access functionality remotely. Unfortunately, to work generally, SOAP is quite complicated, and making SOAP requests is not very straight-forward, requiring XML parsing and generation.

Instead, REST relies on Hyper Text Transfer Protocol (HTTP) to do the heavy lifting. Webservers and server scripts are already built around working within HTTP. To make a request using REST is as simple as a URL request, such as visiting a webpage. The API for a RESTful service can reuse any of HTTP's methods and status codes to signal any errors. Instead of accessing data that's stored in a database through fancy queries and special code, RESTful services allow access that's more similar to a standard filesystem.

The key part of RESTful services, is the declarativeness. A request to GET /widgets/109340 is likely going to get you the data for the widget with an id of 109340. I say "likely" because there's no guarantee. It's up to the implementor. The point is that you can glance at the REST request and know what you expect to be returned. With SOAP, it's much harder to tell whether you have a syntax error.

If /widgets/109340 doesn't exist, instead of passing back a message body, with some specific value to state that the content exists, the server can return a 404 Not Found code, and the user will know that the particular ID doesn't exist. If 403 is returned, the user will know that the item exists, but that they don't have permissions to access it. These request response codes are already supported by programs that make URL requests, because they're common to all servers. This makes REST requests much more resilient.

REST is also flexible on the output format, /widgets/109340 could return a JSON object, but there's no reason it can't return binary data, HTML, XML, SVG, Video, or any other data format. A CDN could use a REST API to serve up versioned content which may or may not be stored on the filesystem: GET /jQuery/1.0.0, GET /jQuery/1.7.1, and GET /jQuery/latest are all RESTful requests.

I'm going to assume you understand what Simple Object Access Protocol (SOAP) is

zzzzBov
  • 174,988
  • 54
  • 320
  • 367
  • State transfer and a declarative interface aren't the same thing at all. State transfer is hyperlinking in resource representations returned to the client, and no server-side application state being stored between calls. This allows many levels of decoupling between the server, client, and application, and thus opens up a world of scalability. A declarative interface might be a prerequisite to enable state transfer, but that doesn't mean they're the same thing. – Merlyn Morgan-Graham Oct 09 '13 at 07:24
  • @MerlynMorgan-Graham, by all means answer the question if you've got a better answer. – zzzzBov Oct 09 '13 at 13:23
  • Just trying to help out. I didn't intend to offend so I apologize if I have :) I will take up your suggestion tho! – Merlyn Morgan-Graham Oct 09 '13 at 17:27
  • 1
    @MerlynMorgan-Graham, I'm not offended in any way, it just seemed like you had more information that I didn't know and that you'd be able to write up a good answer with what you'd already posted. – zzzzBov Oct 09 '13 at 17:48