0

I have read some tutorials on REST API development, One thing i could not understand how a single url worked for different HTTP Request methods for example

GET : api/users/1
POST: api/users/1
PUT: api/users/1

In these cases all urls are same, but action is different. my question is how a API detect the HTTP request method ?? is that HTTP Request method mentioned in url or it can detect automatically?? in php

please clarify me..

Sorry for my poor English..

thanks in advance..

  • Possible duplicate of [PHP detecting request type (GET, POST, PUT or DELETE)](http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete) – Sergey Chizhik Feb 23 '16 at 20:23

1 Answers1

0

When a request is made, what gets sent is literally "GET www.yahoo.com", for instance. You can do this in a telnet session, actually.

Literally, Step 1: connect to port 80 of remote server Step 2: send "GET hostname". Post would be "POST hostname", etc.

It quickly gets more complicated with all of the options that can be sent such as cookies, headers, uploads, ssl, etc. But, the verb is always sent in the request.

If you are asking how to detect in on the server side, there is already a question that answers: PHP detecting request type (GET, POST, PUT or DELETE)

Community
  • 1
  • 1
rfportilla
  • 310
  • 2
  • 15