0

I am a newbie to REST

However, I plan to develop a web application with REST and started with the following code,

$app->get('/users', 'getUsers');
$app->get('/users/:id',    'getUser');
$app->get('/users/search/:query', 'findByName');
$app->post('/users', 'addUser');
$app->put('/users/:id', 'updateUser');
$app->delete('/users/:id',    'deleteUser');

Update :

I use to handle by

domain.com/user/1 (I don't have any confusion in it)

I understand the simplicity of url and using the GET, PUT, POST, DELETE but my major doubt is

If i handle it by

?id=1|action=delete ?id=2|action=insert

and had the conditions inside the page like

splitting the got parameter by the pipe symbol and assigning the actions and if i check like if action is delete, or insert like that , then what is the purpose of using REST ?

Or if i didn't understood the usage of REST, Kindly convey the main purpose and benefits of REST

Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
AngularAngularAngular
  • 3,589
  • 5
  • 25
  • 41
  • I did a quick run-through of RESTful resources here: http://stackoverflow.com/questions/27940690/laravel-routing-does-not-work-with-post/27942607#27942607 – rdiz Jan 14 '15 at 12:45
  • 1
    It sounds like you are proposing putting `GET` / `POST` / etc in the URL instead of in the HTTP Verb. If so, then you're misunderstanding `GET` / `POST` / etc entirely. – Quentin Jan 14 '15 at 12:46
  • REST is an architecture, the way the parameters are sent/received is down to the _protocol_. If you use the HTTP protocol to send your requests, then your question doesn't apply AFAIK do some reading, the wiki pages for REST and the various protocols are quite extensive – Elias Van Ootegem Jan 14 '15 at 12:46
  • @Dencker: Thanks for the reference, i will make use of it – AngularAngularAngular Jan 14 '15 at 12:51
  • @Quentin : I don't get you . You telling i am using the usage of GET/POST wrongly in REST ? – AngularAngularAngular Jan 14 '15 at 12:51
  • @Chennai — It looks like it. – Quentin Jan 14 '15 at 12:52
  • @Quentin : I am just doing the simple curd operations (that too got from reference) Is that behaviour wrong ? – AngularAngularAngular Jan 14 '15 at 12:57
  • @Chennai that would be using [RPC](http://en.wikipedia.org/wiki/Rpc). It's up to you, whether to use RPC or REST, but I advise you to [stand on the shoulder of giants](http://stackoverflow.com/questions/15056878/rest-vs-json-rpc). – moonwave99 Jan 14 '15 at 15:03
  • The uniform interface constraint : http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_5 is about using existing standards instead of reinventing the wheel. The HTTP standard is just one of them. – inf3rno Jan 14 '15 at 16:39

1 Answers1

0

You do not have to add the "verb" (insert,delete,get) in a REST application parameters, that is done by the request already. You can check the request "verb" by $_SERVER['REQUEST_METHOD'] for example so a Get request on user will return the user data, and a Post request would inset a user For example calling http://domain.com/user/10 would return the user data of the user with id=10 if called with a GET Request and would delete said user if called with a DELETE request

Victor Radu
  • 2,262
  • 1
  • 12
  • 18
  • I have updated the question. I use to get the values by domain.com/user/1 (I don't have confusion in it). Do i get any other extra benefit rather than this ? – AngularAngularAngular Jan 14 '15 at 12:59
  • what do you mean any other benefit? you benefits are that you can actually use the verbs in the HTTP protocol and you do not have to add the action as a parameter to the request, more important than this is that you are building an API according to some standardised method, THAT is in itself a great benefit wich will make you a "good developer" and not make the "another developer I have to hit" List of other developers who would use the API – Victor Radu Jan 14 '15 at 13:02