Creating custom web APIs

Let's go ahead and create a miniature, yet full-blown Magento module Magelicious_Boxy that demonstrates the entire flow of creating a custom web API.

We start off by defining a module <MAGELICIOUS_DIR>/Boxy/registration.php as follows:

\Magento\Framework\Component\ComponentRegistrar::register(    \Magento\Framework\Component\ComponentRegistrar::MODULE,    'Magelicious_Boxy',    __DIR__);

We then define the <MAGELICIOUS_DIR>/Boxy/etc/module.xml as follows:

<config>    <module name="Magelicious_Boxy" setup_version="2.0.2"/></config>

We then define the <MAGELICIOUS_DIR>/Boxy/Setup/InstallSchema.php that adds the following table:

$table = $setup->getConnection()  ->newTable($setup->getTable('magelicious_boxy_box'))  ->addColumn( 'entity_id', ...

Get Magento 2 Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.