Service contracts

Magento 2 has introduced Service contracts to enhance the modularity of the application.

You can read more about the idea at DevDocs Magento 2 Service contracts, but lets take a look at this image that I borrowed from the link

msc.jpg

You should immediately notice that:

a. Resource models are wrapped by Service interfaces
b. Models are wrapped by both Data interfaces and Service interfaces
c. Together, the Data interfaces and the Service interfaces do constitute the Service contract layer

The key things that are the benefits behind the idea are:

a. The Service contract layer as defined and implemented in any module, can be used by other Magento modules
b. More importantly, the Service contract layer can be used as an endpoint, i.e. as a web service to expose data read/write capacity to pretty much any remote program (say, by sending JSON).

This way, a Magento 2 module is structured in a more complicated way, but this enables one to implement the headless commerce idea where the platform can be used as a source provider to one or many different so called “heads” which work on different devices with their own non-magento specific UI and non-magento templating mechanism. A step forward, no doubt.

I will attempt to dig into details for both Data interfaces and Service interfaces.

Follows a list of links: