I'm using magento 2.2.5 and created a frontend route like this:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="spin" frontName="spin">
<module name="Neverending_Story" />
</route>
</router>
</config>
How can i allow only POST method request that can access this route ??
Best Answer
Magento request object has a function
$this->getRequest()->getMethod()
which provide the request method name on request object. So using thisgetMethod()
,you can prevent your route from all other request accept POST..Create an observer on event
And on that observer if you will found that the request method
$observer->getEvent()->getRequest()->getMethod()
,then dis-allow the all pages of this routes<route id="spin" frontName="spin">
Call observer from events.xml
Observer code: