CodeIgniter Forums
Add PURGE of RESTful paths for a single resource - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Add PURGE of RESTful paths for a single resource (/showthread.php?tid=72592)



Add PURGE of RESTful paths for a single resource - atsanna - 01-09-2019

Hi everyone,
To quickly create a handful of RESTful paths for a single resource with the resource () method, I needed to implement the purge method to delete all deleted records.
I would like this method to be implemented.
I share the changes I made to the "system\router\RouteCollection.php" file below
I hope it is useful to someone.

I'm very sorry if I'm wrong to post here.

ADD into public function resource
*      // Generates the following routes:
*      HTTP Verb | Path        | Action        | Used for...
*      ----------+-------------+---------------+-----------------
*      PURGE       /photos/            purge           purge all deleted photos

Code:
//=======================
// Added row 874
//=======================
if (in_array('purge', $methods))
{
$this->purge($name . '/purge' , $new_name . '::purge', $options);
}

ADDED after public function delete
Code:
 /**
    * Specifies a route that is only available to PURGE requests.
    *
    * @param $from
    * @param $to
    * @param array $options
    *
    * @return \CodeIgniter\Router\RouteCollectionInterface
    */
   public function purge(string $from, $to, array $options = null): RouteCollectionInterface
   {
       $this->create('purge', $from, $to, $options);

       return $this;
   }


.php   RouteCollection.php (Size: 35.41 KB / Downloads: 59)


RE: Add PURGE of RESTful paths for a single resource - ciadmin - 01-09-2019

Where do you see an HTTP PURGE verb?
Mozilla doesn't recopgnize it - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
Nor can I find any reference to this verb/method in the W3C HTTP materials


RE: Add PURGE of RESTful paths for a single resource - atsanna - 01-09-2019

You are right!
The HTTP PURGE method exists but is not defined in the HTTP RFCs.
I was fooled using Postman ...  Confused
Not being defined as "standard", it makes more sense to manually add the path with the $ routes- method> add ().

I found the answer by following this link ...
https://stackoverflow.com/questions/25857508/what-is-the-http-method-purge

Thank you very much for your support.


RE: Add PURGE of RESTful paths for a single resource - orionstar - 01-09-2019

For example Varnish HTTP cache uses PURGE method, but its a made up HTTP method, not official...