Reputation: 3856
i searched a lot regarding the question in the title and I'm still not really sure what I'm supposed to do. I just heard of RESTful this morning and the more I read about it the more confused I get.
A couple of weeks ago I was supposed to make an PHP/jQuery/AJAX web application that would basically be a simple todo list with multiple users. I learned a lot about ajax and jQuery(thanks to stackoverflow) during the process and I am quite happy with the final result.
The application works like this: The user logs in, and his id is stored in session variable. For example if he clicks on 'Add' button the code looks something like this.
//script.js
$.get("ajax.php",{'action':'new','text': $text, 'list': $selectedList
},
function(msg){
// add a new task and fade it
$(msg).hide().appendTo('.listoftasks').fadeIn();
});
And on the ajax.php
//ajax.php if($_GET['action'] == 'new') add_task($_GET['text'], $_GET['list'], $_SESSION['user_id']);
So, as it turns out an android app for the web app is in the plans and I was asked if I could make a RESTful web service for it. Can anybody point me in the right direction, is it possible to implement that kind of service with an application coded like this because I've read somewhere (among many other things) that it doesn't work with sessions?
It would be great if someone coud at least point me to some basic tutorials, because at this moment this is all very confusing for me.
Thank you for all your help
edit:
Ok thanks everyone, i managed to do what was asked from me with you help and I learned something new, thank you. The problem I have now is authentication. Basically the android app sends request to my api.php page with some variables (id, list_id etc). Now how do I implement some form of authentication so the api.php would only return results for the authenticated user. I've talked to the app developer briefly and basically he would send me username and password through http header (or something like that). How do I get those values on my api.php page? Thank you for all the help :)
Upvotes: 2
Views: 1929
Reputation: 16177
In few words – an a very practical, non academic explanation – a RESTful web service is a web server that answer requests that are structured following a :resource/:action/[:id] pattern.
For example, your users are a resource and you have these actions:
It is a CRUD interface: Create, Read, Update, Destroy.
Your sessions are resources too.
Some resources do not need to be have all CRUD actions.
For the original document that describes the RESTful architecture:
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
For a more practical examination of this matter:
http://www.amazon.com/Service-Oriented-Design-Rails-Addison-Wesley-Professional/dp/0321659368
Upvotes: 5
Reputation: 142044
There is lots of useful information here http://code.google.com/p/implementing-rest/
Be warned, there is more mis-information about REST on the web than there is valid information.
Most of the systems that you will see on the web described as REST are simply HTTP based Remote Procedure Call, APIs. This is a valid architecture, but it is not REST and therefore does not need to comply to the REST constraints, nor does it necessarily gain the benefits of REST.
Upvotes: 3