Top Banner
Hello Everyone!
22

Magento Meetup New Delhi- API

Feb 11, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Magento Meetup New Delhi- API

Hello Everyone!

Page 2: Magento Meetup New Delhi- API

Ratnesh KumarBuilding mobile apps for Android & iOS devices.(Mobikul Department)

Page 3: Magento Meetup New Delhi- API

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.

Page 4: Magento Meetup New Delhi- 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.

Page 5: Magento Meetup New Delhi- API

XYZ Restaurant

**Logos and Trademarks are owned by their respective owners

Page 6: Magento Meetup New Delhi- API

Ways to Access Web Services!

There are two ways to access Web Services.

• Simple Object Access Protocol (SOAP).

• Representational State Transfer Protocol (REST).

Page 7: Magento Meetup New Delhi- API

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.

Page 8: Magento Meetup New Delhi- API

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.

Page 9: Magento Meetup New Delhi- API

ABC Flight Website

**Logos and Trademarks are owned by their respective owners

Page 10: Magento Meetup New Delhi- API

Flight Aggregator Application

**Logos and Trademarks are owned by their respective owners

Page 11: Magento Meetup New Delhi- API

Benefits of API

• Helps making money (ebay)

• Helps saving money (AWS)

• Helps building brand (Google Map)

• Move to the CLOUD (shopify)

• Omni presence (Netflix)

Page 12: Magento Meetup New Delhi- API

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.

Page 13: Magento Meetup New Delhi- API

Authentication

• Basic access authentication.• OAUTH authentication.

Page 14: Magento Meetup New Delhi- API

Basic access authentication

**Logos and Trademarks are owned by their respective owners

Page 15: Magento Meetup New Delhi- API

OAUTH

**Logos and Trademarks are owned by their respective owners

Page 16: Magento Meetup New Delhi- API

How to build API in

Magento 1?

Magento supports both SOAP and RESTful APIs’

Page 17: Magento Meetup New Delhi- API

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)

Page 18: Magento Meetup New Delhi- API

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)

Page 19: Magento Meetup New Delhi- API

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)

Page 20: Magento Meetup New Delhi- API

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}

Page 21: Magento Meetup New Delhi- API

Thank You!

Page 22: Magento Meetup New Delhi- API

You may now ask questions