Magento 2 Api/Data, When To Create It?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question





















  • 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
















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?










share|improve this question





















  • 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












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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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 config etc/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.

enter image description here




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)



  1. If your entities will be used by other modules, then yes, you
    probably want to add a repository.

  2. 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.

  3. 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





  1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html

    1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html

    2. http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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 config etc/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.

    enter image description here




    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)



    1. If your entities will be used by other modules, then yes, you
      probably want to add a repository.

    2. 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.

    3. 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





    1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html

      1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html

      2. http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/






    share|improve this answer
























      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 config etc/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.

      enter image description here




      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)



      1. If your entities will be used by other modules, then yes, you
        probably want to add a repository.

      2. 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.

      3. 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





      1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html

        1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html

        2. http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/






      share|improve this answer






















        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 config etc/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.

        enter image description here




        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)



        1. If your entities will be used by other modules, then yes, you
          probably want to add a repository.

        2. 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.

        3. 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





        1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html

          1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html

          2. http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/






        share|improve this answer












        • With service contracts usage (Api/Data interfaces), it will be
          possible to expose custom module functionality as web API just by
          adding config etc/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.

        enter image description here




        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)



        1. If your entities will be used by other modules, then yes, you
          probably want to add a repository.

        2. 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.

        3. 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





        1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-contracts.html

          1. https://devdocs.magento.com/guides/v2.0/extension-dev-guide/service-contracts/service-to-web-service.html

          2. http://vinaikopp.com/2017/02/18/magento2_repositories_interfaces_and_webapi/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 20 mins ago









        Aditya Shah

        2,5151429




        2,5151429



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke