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:
The way companies exchange data with their trading partners can make or break operational efficiency.…
Modern websites are built to be fast, dynamic, and secure. At the same time, developers,…
The blockchain development landscape has exploded with opportunities. Whether you're building decentralized apps, smart contracts,…
Imagine a device that notifies you about all-day activities, reminds you to take your pills,…
How do you like the new “liquid glass” design on your iPhone? The latest iOS…
As Fortinet devices approach the Fortinet End of Life of their supported lifecycle, many security teams find…