-2

We know the difference between POST and GET, but why should a client state the method type when issuing http requests? Why should it make a difference for the server? in the end, it is the server job to deal with those requests according to their URL and Content. either by redirecting, blocking or accepting and using data (existing in the URL or request body).

Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17
AMD711
  • 11

1 Answers1

2

An endpoint can accept both GET and POST requests (along with PUT, PATCH and DELETE). If the client does not explicitly state what type of request they are sending, the server will interpret it as a GET request (the default).

Consider the following PHP example, sitting on https://api.example.com/resources/:

<?php

if ($_POST["request"]) {
  // Create new resource
}
else if ($_GET["request"]) {
  // List existing resources
}

In both instances, the request parameter is sent to the same page, and different logic is run based on what the method is. But considering the same data is sent to the same page in both instances, the server wouldn't know which one of the two conditions to step into if the client doesn't explicitly specify the method.

In RESTful programming, both the client and server have been programmed to understand the request, but the client has no knowledge of the server itself. It is up to the server to process the request, based off of what the client asks it to do. And the client asks it to do different things by specifying the method.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • But why design for multi actions that is: 1- for the same route. 2- specifically dependant of the http method stated by the client, not anything else. in the first place? – AMD711 Mar 02 '18 at 10:01
  • @AMD711 If you want to know the answer to that question, you need to do your research. Read the linked article. If you *really* want to know why, read the dissertation by Roy Fielding... – Heretic Monkey Mar 02 '18 at 17:12