3

I followed alanstorm's magento 2 guides and now I am in Magento world for a little more than a month. https://alanstorm.com/category/magento-2/#magento-2-mvc

I've come across this tutorial about creating rest-api https://webkul.com/blog/magento2-custom-rest-api/ it says to make a composer.json and I don't actually know why I need this or where to use this.

I didn't make composer.json file to make non-api modules and it worked fine.

1

Basically, composer.json is included in your custom module to define metadata and declare external and third-party dependencies that it needs in order for it to function. As Magento 2 uses composer to package components.

However, your custom module still works if you are using it directly in your Magento webshop(like you are installing it manually) but if you plan or want to submit it to the Magento Marketplace you should include the composer.json file.

0

While a Magento 2 module/extension can function without it, the main purpose of the composer.json file is to let composer manage that module/extension.

The existence of composer.json allows:

  • installing the module through composer
  • composer to figure out the module's/extension's dependencies
  • the upgrade of the module through composer

Also, form what I've read \Magento\Framework\Module\PackageInfo is also related to the existence of the composer.json file, so you might want to take a look at that, too.

Cheers, Radu

  • Thank you Raud! – Jinmo Chong Apr 4 at 21:52
  • It's Radu :) you're welcome! @magefms beat me to it :P – Radu Apr 4 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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