Magento – Difference between the API interfaces in Api and Api/data folders
apimagento2
API interfaces are available in Api and Api/data folders,
what is the basic difference between these two api types?
Best Answer
Data interfaces
Data interfaces are used to maintain the integrity of the data, data interfaces defines all the setters and getters for the related entity. So even if there is any changes in the model or business logic you will always get consistent data. Data interfaces resides in VendorName\ModuleName\Api\Data, so in all the modules you can found data interfaces in Api/Data folders, related model need to implement these interfaces and provide the setters, getters deffinition.
Interfaces
Repository interfaces give access to persistent data entities. interfaces have the following methods:
save(data entity interface): Creates a new record if no id present, otherwise updates an existing record with the specified id.
get(id): Performs a database lookup by id and returns a data entity interface (such as CustomerInterface or AddressInterface).
getList(search criteria): Performs a search for all data entities matching the search criteria and returns a search results interface to give access to the set of matches.
delete(data entity interface): Deletes the specified entity (the key is in the entity).
deleteById(id): Deletes the specified entity when you only have the key for the entity.
basically containers are the equivalent of the core/text_list blocks in magento 1.
"philosophically" they work the same, the only difference is that containers are predefined blocks that only support other child blocks.
Some examples are content, after.body.start, header-wrapper.
You can see all defined containers for example in the Magento/Theme/view/base/page_layout/*.
basically what's defined as <container name="..." /> can be accessed by referenceContainer. what's declared as <block .... /> can be referenced by referenceBlock
Best Answer
Data interfaces
Data interfaces are used to maintain the integrity of the data, data interfaces defines all the setters and getters for the related entity. So even if there is any changes in the model or business logic you will always get consistent data. Data interfaces resides in VendorName\ModuleName\Api\Data, so in all the modules you can found data interfaces in Api/Data folders, related model need to implement these interfaces and provide the setters, getters deffinition.
Interfaces
Repository interfaces give access to persistent data entities. interfaces have the following methods:
save(data entity interface): Creates a new record if no id present, otherwise updates an existing record with the specified id.
get(id): Performs a database lookup by id and returns a data entity interface (such as CustomerInterface or AddressInterface).
getList(search criteria): Performs a search for all data entities matching the search criteria and returns a search results interface to give access to the set of matches.
delete(data entity interface): Deletes the specified entity (the key is in the entity).
deleteById(id): Deletes the specified entity when you only have the key for the entity.
You can check one Example from here : https://webkul.com/blog/magento2-service-contract/