magento meetup new delhi- api
TRANSCRIPT
Story of an UNSUNG HERO
In this era of technology, we all are connected around the world from desktop to mobile devices to laptops to browser.
But how does this happens?
How does data reach from one device to another?
How do different devices interact with each other ?
Behind all this, there is a hero that is API.
Application Programming Interface(API)
What is an API?Api is simply exposing business capabilities (web services) over the internet.
OR
API consists of a set of rules describing how one application can interact with another, and the mechanisms that allow such interaction to happen.
Ways to Access Web Services!
There are two ways to access Web Services.
• Simple Object Access Protocol (SOAP).
• Representational State Transfer Protocol (REST).
SOAP
The Granddaddy of Web Services Interfaces.
• XML based messaging protocol.
• Platform and Language Independent.
• SOAP has built-in stateful operations.
• SOAP is complex, yet well formatted.
REST
The easy way to expose Web Services. (REST + JSON)
• Uses HTTP to perform CRUD.
• Platform and Language Independent.
• REST is naturally stateless.
• REST is easy to understand.
Benefits of API
• Helps making money (ebay)
• Helps saving money (AWS)
• Helps building brand (Google Map)
• Move to the CLOUD (shopify)
• Omni presence (Netflix)
Why we need API?
We need to have a Web API if we want to store and process our data in server and let any other application (web application, mobile application, IoT devices etc.) request and get data from that server if needed.
Create SOAP API in
Magento 1?
Required files to create SOAP apis’
• api.xml (app/code/code_pool/namespace/module_name/etc/api.xml)
• wsdl.xml (app/code/code_pool/namespace/module_name/etc/api.xml)
• Api functionality or business logic (app/code/code_pool/namespace/module_name/Model/Api.php)
Create REST API in
Magento 1?
Required files to create REST apis’
• api2.xml (app/code/code_pool/namespace/module_name/etc/api2.xml)
• Api functionality or business logic (app/code/code_pool/namespace/module_name/Model/Api2/your_api_file.php)
Create API in Magento2?
Required files to create apis’
• webapi.xml (vendor/namespace/module_name/etc/webapi.xml)
• Api functionality or business logic (vendor/namespace/module_name/Api/your_api_file.php)
webapi.xml
<route url="/V1/module_name" method="POST"> <service class="namespace\module_name\Api\your_api_file_name" method="doSomething"/></route>
URL will beyour_domain/V1/module_name POST
Api functionalitypublic function doSomething () {
// your business logic}