REST versus SOAP

Magento supports both SOAP (short for Simple Object Access Protocol) and REST (short for Representational State Transfer) types of communication with the Web API. Authentication methods themselves are not really bound to any of them. We can use the same authentication method and Web API method calls with both SOAP and REST.

Some of the REST specifics we might outline as follows:

  • We run REST Web API calls through cURL commands or a REST client.
  • Requests support HTTP verbs: GET, POST, PUT, or DELETE.
  • A HTTP header requires an authorization parameter, specifying the authentication token with the Bearer HTTP authorization scheme, Authorization: Bearer <TOKEN>. <TOKEN> is the authentication token returned by the Magento token service.
  • We can use the HTTP header Accept: application/<FORMAT>, where <FORMAT> is either JSON or XML.

Some of the SOAP specifics we might outline as follows:

  • We run SOAP Web API calls through cURL commands or a SOAP client.
  • A Web Service Definition Language (WSDL) file is generated only for services that we request. There is no one big merged WSDL file for all services.
  • The Magento Web API uses WSDL 1.2, compliant with WS-I 2.0 Basic Profile.
  • Each Magento service interface that is part of a service contract is represented as a separate service in the WSDL.
  • Consuming several services implies specifying them in the WSDL endpoint URL in a comma-separated manner, for example http://<magento.host>/soap/<optional_store_code>?wsdl&services=<service_name_1>,<service_name_2>.
  • We can get a list of all available services by hitting a URL like http://<SHOP-URL>/soap/default?wsdl_list in the browser.

The following REST and SOAP examples will make extensive use of cURL, which is essentially a program that allows you to make HTTP requests from the command line or different language implementations (like PHP). We can further describe cURL as the console browser, or our view source tool for the web. Anything we can do with various fancy REST and SOAP libraries, we can do with cURL as well; it is just considered to be a more low-level approach.

Doing SOAP requests with cURL or anything else that does not have WSDL/XML parsing implemented internally is cumbersome. Thus, using PHP SoapClient or something more robust is a must. SoapClient is an integrated, actively maintained part of PHP, and is thus generally available.

With negative points being pointed, we will still present all of our API calls with console cURL, PHP cURL, and PHP SoapClient examples. Given that libraries abstract so much functionality, it is absolutely essential that a developer has a solid understanding of cURL, even for making SOAP calls.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.86.155