What is RESTful?

Can someone explain to me - in plain terms - what “RESTful” is??

(I looked online and my eyes glazed over after the first paragraph…) :blush:

Thanks,

Debbie

The short, short, short version would be “embracing HTTP as a messaging layer.” Beyond that it means lots of different things to different people. Perhaps you’ve got a more pointed question here . . .

I was looking for Streaming Video Web Hosts and I saw that term a couple of times…

I’ve heard developers at work use it too.

Never really knew what it meant, and was hoping to get a better understanding so when it comes up again I’ll know what it is.

Debbie

Usually it’s a type of web service or API, which you can interface with to get data from external systems into your system.

RESTful is opposed to something like SOAP. They’re both usually web services, but they work differently. The big key with RESTful web services is they are “stateless”, which means each transaction between it is a complete entity all on it’s own. (As opposed to SOAP where you may do something like login, then have a persisting connection).

The other big thing is it usually uses the HTTP layer as it’s meant to be used. A lot of APIs have you do something like get your info from a URL:


api.php?info=books&name=fun&page=10

A RESTful API would have you put this as a URL usually


api/books/fun/10

Which translates into a HTTP GET request:


HTTP 1.1 GET /api/books/fun/10

That’s not much different. But say you want to create a new user. A non-RESTful API may have you do something like:


makeuser.php?name=bob&password=tooth

which translates to:


HTTP 1.1 GET /makeuser.php?name=bob&password=tooth

However, that’s not using HTTP GET properly, since GET should only get info and never change it.

A proper RESTful API would likely have you use PUT instead. Something like:


HTTP 1.1 PUT /makeuser/bob/tooth

Making proper use of the HTTP protocol.

samanime,

Interesting explanation!

Thanks,

Debbie

@samanime; minor point, but IIRC POST is used to create entities whereas PUT is used for updating existing ones.

Other than that I completely agree with what you said :slight_smile:

Completely correct, thanks for the correction. =p

I’ve heard of many variations. Some developers suggest that if you’re querying or doing any kind of CRUD database operations that RESTful service is the way to go. If you’re doing any actions through HTTP, like login/logout/search/verbs than you should use Web Service. Then to make things more confusing, they throw the term RESTful Web Service. Anyways, I look at RESTful service as a nice URL pattern service and nothing more.

Here is a great write-up of the various types of web service APIs: http://blog.steveklabnik.com/posts/2012-02-13-an-api-ontology

That is wrong when considering a true REST approach.

PUT is used both to create and replace entities.

POST is used to create records under another entity.

Example:
-To create/update a user account we would use PUT.
-To add another chapter to a book we would use POST (in this case book would be an entity already created by PUT).

That is a very simple example, but I hope it is sufficient to describe the difference.

Personally I don’t like a pure/true REST approach to an API, as it does limit you somewhat in what the API can and cannot do.

The benefit of a pure REST approach is speed, if you can use this you will see that it is a lot faster than other options if the web server that host the API is configured properly.

With other words, don’t be afraid to go for a “*******” (hybrid) API, taking the best part from the different architecture that is out there.

EDIT: Well, I guess the “bad word” system is tuned a little too high when it remove valid words like b a s t a r d…