22

I've read a couple of definitions and discussion on REST and/or RESTful applications, but I still do not understand the real meaning of it.

I usually work with the apps which either fetch data via GET or send data via POST to some web service (usually a PHP script) which then either get data from the database or do writing into the database.

Now, is this a RESTful app? If not, what would be a RESTful app? What is difference between RESTful concept and the concept I worked so far with? Please explain via an example.

Also, someone is talking about the REST and someone about RESTful apps. I found that the REST term refers to the theoretical concept, while RESTful is used when we talk about the specific app. Is this right or there are real differences between REST and RESTful apps?

deviDave
  • 2,953

4 Answers4

14

The key attributes of a RESTful applications are: All communication is via http GET,POST,PUT,DELETE AND all items are addressed via a standard URL of the form http://your.site.com/salesapp/salesperson/0000001/details i.e. only a pure URL with no parameters etc. the URL identifies the thing the GET,POST,PUT,DELETE identifies what you want to do to it.

The main reason for doing this is that you automatically have a stateless service which can be load balanced, failed over etc. etc.

The sheer simplicity of the scheme makes for a very clean interface, totally decoupling the client from any particular back-end implementation.

7

REST stands for Representational State Transfer. If your software conforms to the REST Constraints then it is considered to be RESTful.

Right, now that I've shamelessly ripped from Wikipedia, what does this really mean? It effectively means using the inbuilt HTTP commands such as GET, POST, PUT, DELETE and a few other rarer ones to communicate back and forth between a client and server.

What you're doing sounds like its a RESTFul app. However, there's a large difference between well designed and piles o' junk RESTFul web services. For example the PHP code at the other end of the GET might execute state change, which would be considered wrong since a GET is seen as a read only operation. There are subtle differences between how POST (new) and PUT (replace) are used as well.

The Wikipedia article on this is actually really good, so I'll stop here.

4

Before going further, this related question may help you

The difference between REST and RESTful is simply semantics. REST is an architectural style applied to a client-server relationship. RESTful is simply a way of telling your clients that you use REST.

Many web applications claim to be RESTful, but actually are only partially conformant to the REST Constraints (as Martijn Verburg has also referenced in his answer). I'll just list them here but I strongly urge you to read the article:

  • Client–server
  • Cacheable
  • Layered system
  • Code on demand (optional)

Since you mention that you work on the client side it might be helpful to see what a REST architecture will give and expect from you as a connecting client. Although REST is not HTTP it is by far the most popular protocol that supports what REST is so I'll frame my example around that.

Your client will be expected to:

  • use HTTP verbs (e.g. GET, POST, PUT, DELETE, OPTIONS, PATCH) to perform relevant operations
  • offer Accept headers and understand Content-Type headers (e.g. you receive some XML you've never seen before but you can use a referenced XSD to create a client-side domain model to present to your user)
  • follow offered links in a Content-Type you understand (e.g. get your user or your application to infer that <link rel="pay" href="http://example.org/orders(1)/payment"> in HTML expresses a state transition to create a payment resource through a POST with a body containing some XML that represents the payment details like credit card number, amount and so on)
  • react correctly to the wide range of HTTP status codes

If it does the above then it can be thought of as being a REST client, you may want to call it a "RESTful app" but that would rather imply that you're using REST on the client side which is incorrect so best to avoid the term.

Gary
  • 24,440
3

RESTful means that the interface is a set of objects, that can be read and updated (and possibly deleted). That is there are no multi-parameter queries (only parameter is the object you want to read) and there is only one type of operation that changes anything on the server, upload of new state.

These limitations ensure that all requests are idempotent (sending them multiple times does not have any extra effect to sending them once). This is important, because network may fail anytime and not deliver any request or response and with idempotent requests you just send it again and don't have to do complicated recovery.

Jan Hudec
  • 18,410