Using REST with PHP the HTTP DELETE method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Using REST with PHP the HTTP DELETE method

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

there should be!
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Kieran Huggins wrote:there should be!
uhm...are you serious? 8O
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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...
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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...?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Post Reply