Magento 2 Api/Data, When To Create It?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have fairly simple REST API request to get guest country code by his ip.
In my block file this works perfectly fine when using curl:
$url = "http://........./".$guestIp."?access_key=".$access_key.$jsonOutput;
$this->_curl->get($url);
$response = $this->_json->unserialize($this->_curl->getBody());
$countryCode = $response['country_code'];
return $countryCode;
Now when should I create Api/Data interfaces, repository interfaces in this case if it is needed?
magento2 api rest curl
add a comment |Â
up vote
1
down vote
favorite
I have fairly simple REST API request to get guest country code by his ip.
In my block file this works perfectly fine when using curl:
$url = "http://........./".$guestIp."?access_key=".$access_key.$jsonOutput;
$this->_curl->get($url);
$response = $this->_json->unserialize($this->_curl->getBody());
$countryCode = $response['country_code'];
return $countryCode;
Now when should I create Api/Data interfaces, repository interfaces in this case if it is needed?
magento2 api rest curl
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have fairly simple REST API request to get guest country code by his ip.
In my block file this works perfectly fine when using curl:
$url = "http://........./".$guestIp."?access_key=".$access_key.$jsonOutput;
$this->_curl->get($url);
$response = $this->_json->unserialize($this->_curl->getBody());
$countryCode = $response['country_code'];
return $countryCode;
Now when should I create Api/Data interfaces, repository interfaces in this case if it is needed?
magento2 api rest curl
I have fairly simple REST API request to get guest country code by his ip.
In my block file this works perfectly fine when using curl:
$url = "http://........./".$guestIp."?access_key=".$access_key.$jsonOutput;
$this->_curl->get($url);
$response = $this->_json->unserialize($this->_curl->getBody());
$countryCode = $response['country_code'];
return $countryCode;
Now when should I create Api/Data interfaces, repository interfaces in this case if it is needed?
magento2 api rest curl
magento2 api rest curl
asked 33 mins ago
Lukas G
505
505
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago
add a comment |Â
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
- With service contracts usage (Api/Data interfaces), it will be
possible to expose custom module functionality as web API just by
adding configetc/webapi.xml
- Improved capabilities for integration with 3rd party systems based on
service contracts will be added in the future, as well as queue
support. - If there is another module dependent on your module, it can just rely
on service interfaces. This reduces coupling between modules and
minimizes risk of accidental breaking of dependent module.
Now when should I create Api/Data interfaces, repository interfaces in
this case if it is needed?
- Service contracts enhance the modularity of Magento. They enable
Magento and third-party developers to report system dependencies
through composer.json files and, consequently, guarantee
compatibility among Magento versions. This compatibility ensures that
merchants can easily upgrade Magento. - Data entities are a side benefit of service contracts. The database
tables that normally support these entities can be complicated. For
example, some attributes might be stored in an EAV table, so a set of
MySQL database tables might define a single data entity . Data
entities in a service contract reveal a simpler data model than the
data model in an underlying relational database schema . Eventually,
you will be able to use different storage technologies for different
data collections. For example, you could use a NoSQL database to
replace product tables.
Using the @api
tag
- Backward compatibility can be indicated by the use of @api. For more
information, see Backward compatibility.
Magento 2 Api/Data, When To Create It?
As always, the answer is “It dependsâ€Â. (In Vinai Kopp's words)
- If your entities will be used by other modules, then yes, you
probably want to add a repository. - There is another factor that should be added into the equation: in
Magento 2, repositories can easily be exposed as Web API - that is
REST and SOAP - resources. - If that is interesting to you because of third party system
integrations or a headless Magento setup, then again, yes, you
probably want to add a repository for your entity.
For more Information
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html- https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html
- http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
- With service contracts usage (Api/Data interfaces), it will be
possible to expose custom module functionality as web API just by
adding configetc/webapi.xml
- Improved capabilities for integration with 3rd party systems based on
service contracts will be added in the future, as well as queue
support. - If there is another module dependent on your module, it can just rely
on service interfaces. This reduces coupling between modules and
minimizes risk of accidental breaking of dependent module.
Now when should I create Api/Data interfaces, repository interfaces in
this case if it is needed?
- Service contracts enhance the modularity of Magento. They enable
Magento and third-party developers to report system dependencies
through composer.json files and, consequently, guarantee
compatibility among Magento versions. This compatibility ensures that
merchants can easily upgrade Magento. - Data entities are a side benefit of service contracts. The database
tables that normally support these entities can be complicated. For
example, some attributes might be stored in an EAV table, so a set of
MySQL database tables might define a single data entity . Data
entities in a service contract reveal a simpler data model than the
data model in an underlying relational database schema . Eventually,
you will be able to use different storage technologies for different
data collections. For example, you could use a NoSQL database to
replace product tables.
Using the @api
tag
- Backward compatibility can be indicated by the use of @api. For more
information, see Backward compatibility.
Magento 2 Api/Data, When To Create It?
As always, the answer is “It dependsâ€Â. (In Vinai Kopp's words)
- If your entities will be used by other modules, then yes, you
probably want to add a repository. - There is another factor that should be added into the equation: in
Magento 2, repositories can easily be exposed as Web API - that is
REST and SOAP - resources. - If that is interesting to you because of third party system
integrations or a headless Magento setup, then again, yes, you
probably want to add a repository for your entity.
For more Information
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html- https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html
- http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/
add a comment |Â
up vote
2
down vote
accepted
- With service contracts usage (Api/Data interfaces), it will be
possible to expose custom module functionality as web API just by
adding configetc/webapi.xml
- Improved capabilities for integration with 3rd party systems based on
service contracts will be added in the future, as well as queue
support. - If there is another module dependent on your module, it can just rely
on service interfaces. This reduces coupling between modules and
minimizes risk of accidental breaking of dependent module.
Now when should I create Api/Data interfaces, repository interfaces in
this case if it is needed?
- Service contracts enhance the modularity of Magento. They enable
Magento and third-party developers to report system dependencies
through composer.json files and, consequently, guarantee
compatibility among Magento versions. This compatibility ensures that
merchants can easily upgrade Magento. - Data entities are a side benefit of service contracts. The database
tables that normally support these entities can be complicated. For
example, some attributes might be stored in an EAV table, so a set of
MySQL database tables might define a single data entity . Data
entities in a service contract reveal a simpler data model than the
data model in an underlying relational database schema . Eventually,
you will be able to use different storage technologies for different
data collections. For example, you could use a NoSQL database to
replace product tables.
Using the @api
tag
- Backward compatibility can be indicated by the use of @api. For more
information, see Backward compatibility.
Magento 2 Api/Data, When To Create It?
As always, the answer is “It dependsâ€Â. (In Vinai Kopp's words)
- If your entities will be used by other modules, then yes, you
probably want to add a repository. - There is another factor that should be added into the equation: in
Magento 2, repositories can easily be exposed as Web API - that is
REST and SOAP - resources. - If that is interesting to you because of third party system
integrations or a headless Magento setup, then again, yes, you
probably want to add a repository for your entity.
For more Information
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html- https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html
- http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
- With service contracts usage (Api/Data interfaces), it will be
possible to expose custom module functionality as web API just by
adding configetc/webapi.xml
- Improved capabilities for integration with 3rd party systems based on
service contracts will be added in the future, as well as queue
support. - If there is another module dependent on your module, it can just rely
on service interfaces. This reduces coupling between modules and
minimizes risk of accidental breaking of dependent module.
Now when should I create Api/Data interfaces, repository interfaces in
this case if it is needed?
- Service contracts enhance the modularity of Magento. They enable
Magento and third-party developers to report system dependencies
through composer.json files and, consequently, guarantee
compatibility among Magento versions. This compatibility ensures that
merchants can easily upgrade Magento. - Data entities are a side benefit of service contracts. The database
tables that normally support these entities can be complicated. For
example, some attributes might be stored in an EAV table, so a set of
MySQL database tables might define a single data entity . Data
entities in a service contract reveal a simpler data model than the
data model in an underlying relational database schema . Eventually,
you will be able to use different storage technologies for different
data collections. For example, you could use a NoSQL database to
replace product tables.
Using the @api
tag
- Backward compatibility can be indicated by the use of @api. For more
information, see Backward compatibility.
Magento 2 Api/Data, When To Create It?
As always, the answer is “It dependsâ€Â. (In Vinai Kopp's words)
- If your entities will be used by other modules, then yes, you
probably want to add a repository. - There is another factor that should be added into the equation: in
Magento 2, repositories can easily be exposed as Web API - that is
REST and SOAP - resources. - If that is interesting to you because of third party system
integrations or a headless Magento setup, then again, yes, you
probably want to add a repository for your entity.
For more Information
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html- https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html
- http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/
- With service contracts usage (Api/Data interfaces), it will be
possible to expose custom module functionality as web API just by
adding configetc/webapi.xml
- Improved capabilities for integration with 3rd party systems based on
service contracts will be added in the future, as well as queue
support. - If there is another module dependent on your module, it can just rely
on service interfaces. This reduces coupling between modules and
minimizes risk of accidental breaking of dependent module.
Now when should I create Api/Data interfaces, repository interfaces in
this case if it is needed?
- Service contracts enhance the modularity of Magento. They enable
Magento and third-party developers to report system dependencies
through composer.json files and, consequently, guarantee
compatibility among Magento versions. This compatibility ensures that
merchants can easily upgrade Magento. - Data entities are a side benefit of service contracts. The database
tables that normally support these entities can be complicated. For
example, some attributes might be stored in an EAV table, so a set of
MySQL database tables might define a single data entity . Data
entities in a service contract reveal a simpler data model than the
data model in an underlying relational database schema . Eventually,
you will be able to use different storage technologies for different
data collections. For example, you could use a NoSQL database to
replace product tables.
Using the @api
tag
- Backward compatibility can be indicated by the use of @api. For more
information, see Backward compatibility.
Magento 2 Api/Data, When To Create It?
As always, the answer is “It dependsâ€Â. (In Vinai Kopp's words)
- If your entities will be used by other modules, then yes, you
probably want to add a repository. - There is another factor that should be added into the equation: in
Magento 2, repositories can easily be exposed as Web API - that is
REST and SOAP - resources. - If that is interesting to you because of third party system
integrations or a headless Magento setup, then again, yes, you
probably want to add a repository for your entity.
For more Information
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html- https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html
- http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/
answered 20 mins ago


Aditya Shah
2,5151429
2,5151429
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245866%2fmagento-2-api-data-when-to-create-it%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
the purpose of a API and Data repository is to hide the storage related logic. A client of a repository should not care whether the returned entity is held in memory in an array, is retrieved from a MySQL database, fetched from a remote API or from a file.
– Aditya Shah
28 mins ago