I am developing a client - server web service. The front end is build with html/javascript/jquery/jqm
and the back end with php/mysql
.
When the client starts it has a static id
(never changes) and a dynamic-token
(that means it may or may not change). For this reason every time the client starts we register him to our server we make a POST
request to our server where in the body we have a JSON file with the id and token
. The post request is made to a php script that looks like this : myserver.com/register.php
, The php script takes the id and token
and makes a query to the database to see if they exist. If the id
doesnt exist it creates
a new record. If it exists , it checks if the token
has been changed so it updates
.
From the client the user can subscribe to a number of events (lets say 10). The events are presented in a list with checkboxes. The user checks the events that he wishes to subscribe and presses a subscribe button. When the subscribe button is hit , a POST
request is made to a php script that in the body has a json file with the id
of the user and all the names of the events with a boolean (subscribe or not subsribe) eg
id: xxxxxx
event1: 1
event2: 0
event3: 0
event4: 1
...
The php script looks like this : myServer/subscribe.php
. When the the request arrives the php file reads the JSON that was received. He searches for the id
in the database and then he checks the names of the events and the booleans that were sent. If it is 1 he subscribes the user. If is 0 he unsubscribe the user. If the user was already subscribed and he subscribes again nothing happens. Same for the unsubscription.
Finally , when the user enters the subscription page , a POST
request is made to the server with a JSON file in the body that has the id
of the user. The request is made on a php file that looks like myServer/whereSubsribed.php
. This php file , gets the id
and looks in the database in which events this id
is subscribed to. When it finishes it responds(makes an echo) to the client with a json
file that has all the events that the user is already subscribed , so that when the checkboxes are loaded , the events in which the user is already subscribed can seem checked.
Is the above service Rest ? I have a really really hard time to understand what is Rest and what is not. What i understand:
I know that i should use POST PUT DELELE GET but i can do everything with just POST as u saw. Then why use them? I know that Rest is about nouns and not verbs , is about resources and not actions. I have NO idea what this means IN PRACTICE.
Can someone please , in this specific case that i describe , give a description of how a Rest web service would look like? How is it possible that i dont have actions like subscribe/unsubscribe/register ?
I hope that by giving me an example i can finally understand what is Rest. At this point maybe i should say that i dont know what is SOAP either. When i started developing my service i just made it like this because thats what i thought is the correct way. Then i learned about the Rest/Soap thing. So is Rest another way that my service could be done and if yes please take some time and explain me how?
Thank you very very much for reading this long post.
**If you are kind enough to give me an answer , please dont give me a definiton or a theorytical approach on the subject. I ve read almost everything that needs to be read. I am also a new html/php scripter , so i would appreciate if you could give me an example with the exact same service that i described. How it would look if it was to be Restful would be great to understand i think.
EDIT
The way i see it , i used HTTP requests (POST) to push some data (id , token , etc) to a specific action/php script(subscribe , register , whereSubscribed).
Rest should be the exact oposite? Send actions through HTTP (post put delete update) to a resource(a user an event).
Does that mean that all the programming would change too? I dont understand how it would be possible to not have the scripts that i wrote. How can a subscription be made programaticaly when you dont have the php script to do so?!