Skip to content

M2 : Override/Intercept REST API POST params

ok then

in your di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
	<type name="Magento\Webapi\Controller\Rest\Router">
		<plugin disabled="false" name="YourModule_ModuleName_Plugin_Magento_Webapi_Controller_Rest_Router" sortOrder="10" type="YourModule\ModuleName\Plugin\Magento\Webapi\Controller\Rest\Router"/>
	</type>
</config>

and then finally, use pluginĀ  ‘before’

<?php


namespace YourModule\ModuleName\Plugin\Magento\Webapi\Controller\Rest;

/**
 * Class Router
 * @package YourModule\ModuleName\Plugin\Magento\Webapi\Controller\Rest
 */
class Router
{

    /**
     * @param \Magento\Webapi\Controller\Rest\Router $subject
     * @param $request
     */
    public function beforeMatch(
        \Magento\Webapi\Controller\Rest\Router $subject,
        $request

    ) {

        $dataRequest = $request->getRequestData();
        
        /* your override script here */
        

            return [$request];
        }

    }


}

 

Comments are closed.