A
A
Alexey Konovalov2018-10-31 18:43:26
RESTful API
Alexey Konovalov, 2018-10-31 18:43:26

What is the advantage of using PUT and DELETE methods?

Hello! I have an API to get data from a server in php. Completely self-written, but android application developers ask to use the PUT and DELETE methods along with GET and POST.
What is the advantage of this approach? After all, when determining on the server which method is used, we still know in advance what to do with such a request ...

<?php
$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
  case 'PUT':
    //....
    break;
  case 'POST':
    //....
    break;
  case 'GET':
    //....
    break;
  case 'DELETE':
    //....
    break;
}

Perhaps I don't understand the architecture where this would be useful... Kick in the right direction...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-10-31
@AXP-dev

If you have a REST API, then it is customary to use it that way.
GET - get
POST - add
PUT - update
DELETE - delete
This reads well and it's immediately clear what these requests are doing.
The most banal example.
We have news with id = 10. We either need to edit/delete/get it. And for this we do not need to come up with an additional URL or parameters.
GET /news/10- get data
PUT /news/10- update data
DELETE /news/10- delete
Without these methods there was something like
GET /news/10- get data
POST /news/10/update- update data
POST /news/10/delete- delete

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question