2

Is there any pre/post dispatch events for the Magento 2 web API (REST/SOAP) ?

3 Answers 3

1

There are no events in Magento 2 web APIs, but it is possible to extend any public method in the system using befor/after/around plugins. Also see why it is better to use plugins instead of observers.

5
  • I was also thinking the same, but just wanted to be sure before creating a plugin for this Commented Jan 15, 2016 at 6:45
  • Just wanted to clarify, that you want to extend something in the framework itself, not just add custom field to the API request/response, right? If just add new field then extension attributes is the way to go. Commented Jan 15, 2016 at 7:45
  • I just wanted to log the requests sent to the Web API of magento REST or SOAP for audit purposes Commented Jan 15, 2016 at 9:14
  • Then plugin should be good. Commented Jan 15, 2016 at 10:53
  • Already implemented and it is working as expected Thanks for you answer!! Commented Jan 15, 2016 at 14:37
2

If you want to add something to the response you may want to look into extension_attributes. Here is description in magento docs and here another question on stack

0
0

I don't know maybe this is a dirty way, override this class

Magento\Webapi\Controller\Rest\Router::match()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.