Page 1 of 1

Using REST with PHP the HTTP DELETE method

Posted: Fri Jan 19, 2007 10:03 am
by kendall
Hi guys,

I have been reading up on this REST API being compared as easier/ faster than SOAP...I came across the use of a DELETE and PUT HTTP Methods

now i get the idea that a POST method is $_POST in PHP GET would be $_GET but
DELETE ?
is there a $_DELETE? lol im laughing here but i serious about the question

Posted: Fri Jan 19, 2007 10:08 am
by Kieran Huggins
there should be!

Posted: Fri Jan 19, 2007 12:52 pm
by kendall
Kieran Huggins wrote:there should be!
uhm...are you serious? 8O

Posted: Fri Jan 19, 2007 1:21 pm
by Kieran Huggins
Totally! though I haven't thought it through really...

These are all the current pre-defined variables:
http://www.php.net/manual/en/language.v ... efined.php

There's no $_DELETE or $_PUT

I guess come to think of it DELETE and PUT commands don't really return anything substantial to the user...

Posted: Fri Jan 19, 2007 1:54 pm
by kendall
Well i was reading some stuff concerning AJAX and PHP using REST and they were talking about using a "DELETE" HTTP method that you can use with a REST API...but im not understanding the process if you use PHP with REST

Posted: Fri Jan 19, 2007 2:03 pm
by Kieran Huggins
DELETE and PUT are handled by apache - just like GET and POST are.

When you try to GET or POST to a resource (file) that apache identifies as "php parsable" apache will then invoke PHP to handle the request on it's behalf. You ca still DELETE or PUT a resource using just apache, but I doubt it woul have a reason to invoke PHP.

Does that make sense to everyone else?

Posted: Fri Jan 19, 2007 2:04 pm
by kendall
Kieran Huggins wrote:DELETE and PUT are handled by apache - just like GET and POST are.

When you try to GET or POST to a resource (file) that apache identifies as "php parsable" apache will then invoke PHP to handle the request on it's behalf. You ca still DELETE or PUT a resource using just apache, but I doubt it woul have a reason to invoke PHP.

Does that make sense to everyone else?
8O :? lol...?

Posted: Fri Jan 19, 2007 11:40 pm
by volka
Let's say you have a script /test.php
Now this script is called by a browser because the user as clicked a link <a href="/test.php?param1=value1">
The request header contains

Code: Select all

GET /test.php?param1=value1 HTTP/1.1
Host: localhost
and echo $_SERVER['REQUEST_METHOD'] in test.php prints GET.
Now instead of GET DELETE is used as method

Code: Select all

DELETE /test.php?param1=value1 HTTP/1.1
Host: localhost
$_SERVER['REQUEST_METHOD'] will be DELETE, anything else is more or less the same.