Table of Contents
API (Application Programming Interface) is an extremely important part of systems in general and Magento 2 in particular. We will learn the way to create a custom API in Magento 2.
We need a tool to interact with the API, we will use Postman, one of the most popular tools.
You can try to Download
First of all, we will create a new module with the following directory structure:
Firstly, we must define the API in etc/webapi.xml as below:
In there:
Next, we need to create an interface class as Api/FirstApiInterface.php:
The Mode/firstApi.php has the below content:
Finally, we need to create a preference at etc/di.xml as follow:
We need to run the following commands for the module to work:
To verify the result, we create a request in Postman with its URL:
https://localhost/rest/all/V1/landofcode-firstapi/hello?name=LandofCode
The results response:
Good luck to you!
Read more:
Vanta vs Drata — According to Cybersecurity Ventures, global cybercrime is set to cost $10.5…
Salesforce cybersecurity threats 2025 are becoming more advanced as cybercriminals increasingly target CRM platforms that…
Custom web design for business growth is essential in today’s highly competitive and fast-paced digital…
Software Development Models have evolved dramatically as technology and user expectations continue to grow. These…
Travel apps are the new-age way of breaking down the travel hard work people used…
In today’s eCommerce landscape, customer support defines brand loyalty. Shoppers expect instant, personalized, and multilingual…