Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

A year ago i developed an iOS application that was connecting to a server with HTTP requests exchanging JSON files, etc... I was told at that time that the server was a web (REST) service. I didnt care much since for me it was just a black box.

Recently, I've been developing a hybrid mobile application where i use native code + jQuery mobile for the front-end part and PHP + MySQL for the back-end part. The application is for registering new users to the database, having users to subscribe in various kinds of events, get notifications on them, etc...

So for all the communication between the front-end (client) and back-end (server), I make HTTP requests (POST) and Ajax calls using JSON files. For example, if I have a subscribe button and is clicked, I make an Ajax POST request sending in the body a JSON file with all the information needed, like user ID and categories to subscribe, to a PHP script. The PHP script then makes all the necessary actions in the database.

Is this a RESTful Web Service? I am a bit confused on the definition of REST. According to Wikipedia REST is:

REST-style architectures conventionally consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses.

So is what I am building a RESTful Web Service? Also do we call REST only the server part or in general the client-server architecture?

From other questions I read that a non-REST web service would manage a database like:

/user_create
/user?id=xxx
/user_edit?id=xxx
/user_delete?id=xxx

and a REST web service would just "expose an API with a single base resource":

/user
/user/xxx

I'm really having difficulty understanding what these things mean... Could someone try to explain to me when a service is a REST web service, maybe by giving me an example of what it is and what it is not?

share|improve this question
    
Have you read the Wikipedia article? :) en.wikipedia.org/wiki/Representational_state_transfer Edit: n/m. I see that you did. However I believe this question would do better on StackOverflow..? –  Patrik Alienus Jun 20 '13 at 18:04
    
This question cannot be moved to stack overflow because the poster is block from asking questions there. –  Stephen Ostermiller Jun 20 '13 at 18:34
add comment

2 Answers

The question What exactly is RESTful programming? on Stack Overflow has many very good answers - try reading through them all, perhaps something will click. I particularly like the conciseness of this answer.

My take on REST: a RESTful architecture means that each entity is accessed and modified through the same URL. To accomplish different actions, you use different HTTP "verbs" (also known as CRUD):

  • Creating entities is done via POST
  • Retrieving entities is done via GET (usually, just fetching one URL)
  • Updating is done via PUT
  • Deleting is done via DELETE

Taking the user example, each individual user is an entity. The non-REST example you included in the question gives you completely different URLs for creating, accessing and deleting the user.

In the REST example you have a base path, /user, and if you want to create a user you send a POST request to it along with the required parameters to create a user. Then to get a user's details, you send a GET request to /user/123 and so on.

share|improve this answer
    
@Michael I don't think so, the question I linked says POST for creating and PUT for updating. –  DisgruntledGoat Jul 12 '13 at 10:53
add comment

A service is RESTful if all the input data can be in the URL. Either in the path, or in the query parameters is in the URL, so all of your examples are RESTful.

This is in contrast to a protocol like SOAP which requires an XML document uploaded as a POST request.

share|improve this answer
1  
I don't think this is correct. This SO question implies POST is valid: stackoverflow.com/questions/630453/put-vs-post-in-rest –  DisgruntledGoat Jun 20 '13 at 19:39
    
POST can be used with REST, but it is never required. SOAP requires the use of a POSTed file upload for each request. –  Stephen Ostermiller Jun 21 '13 at 1:25
1  
It's my understanding that POST is required for creating objects via REST. –  DisgruntledGoat Jun 21 '13 at 11:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.