Creating custom Web APIs

Magento comes with a solid number of API methods that we can call. However, sometimes this is not enough, as our business needs dictate additional logic, and we need to be able to add our own methods to the Web API.

The best part of creating our own API's is that we do not have to be concerned about making them REST or SOAP. Magento abstracts this so that our API methods are automatically available for REST and for SOAP calls.

Adding new API's conceptually evolves around two things: defining business logic through various classes, and exposing it via the webapi.xml file. However, as we will soon see, there is a lot of boilerplate to it.

Let's create a miniature module called Foggyline_Slider, on which we will demonstrate ...

Get Magento 2 Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.