Model data sharing in rails using http










0















I have two rails app. Let's say App1 and App2. App1 has a model which is the core of my business and App2 wanted to use that.



One approach I was thinking was to create PORO which mimics ActiveRecord functionality but instead of interacting with the DB, it will interact with App1 over HTTP or https.



For example:



class User < NetworkRecord
def self.find(id)
new.find(id)
end

def find(id)
endpoint = 'https:app1.com/user'
get(endpoint, id: id )
end
end


class NetworkRecord
def get(endpoint, params)
Httparty.get(endpoint, params)
end
end


I am not sure whether this approach is too intelligent or right, because we are giving some functionality of ActiveModel to an Object without inheriting from it.



If you know any better way to achieve the same thing, please let me know.










share|improve this question


























    0















    I have two rails app. Let's say App1 and App2. App1 has a model which is the core of my business and App2 wanted to use that.



    One approach I was thinking was to create PORO which mimics ActiveRecord functionality but instead of interacting with the DB, it will interact with App1 over HTTP or https.



    For example:



    class User < NetworkRecord
    def self.find(id)
    new.find(id)
    end

    def find(id)
    endpoint = 'https:app1.com/user'
    get(endpoint, id: id )
    end
    end


    class NetworkRecord
    def get(endpoint, params)
    Httparty.get(endpoint, params)
    end
    end


    I am not sure whether this approach is too intelligent or right, because we are giving some functionality of ActiveModel to an Object without inheriting from it.



    If you know any better way to achieve the same thing, please let me know.










    share|improve this question
























      0












      0








      0








      I have two rails app. Let's say App1 and App2. App1 has a model which is the core of my business and App2 wanted to use that.



      One approach I was thinking was to create PORO which mimics ActiveRecord functionality but instead of interacting with the DB, it will interact with App1 over HTTP or https.



      For example:



      class User < NetworkRecord
      def self.find(id)
      new.find(id)
      end

      def find(id)
      endpoint = 'https:app1.com/user'
      get(endpoint, id: id )
      end
      end


      class NetworkRecord
      def get(endpoint, params)
      Httparty.get(endpoint, params)
      end
      end


      I am not sure whether this approach is too intelligent or right, because we are giving some functionality of ActiveModel to an Object without inheriting from it.



      If you know any better way to achieve the same thing, please let me know.










      share|improve this question














      I have two rails app. Let's say App1 and App2. App1 has a model which is the core of my business and App2 wanted to use that.



      One approach I was thinking was to create PORO which mimics ActiveRecord functionality but instead of interacting with the DB, it will interact with App1 over HTTP or https.



      For example:



      class User < NetworkRecord
      def self.find(id)
      new.find(id)
      end

      def find(id)
      endpoint = 'https:app1.com/user'
      get(endpoint, id: id )
      end
      end


      class NetworkRecord
      def get(endpoint, params)
      Httparty.get(endpoint, params)
      end
      end


      I am not sure whether this approach is too intelligent or right, because we are giving some functionality of ActiveModel to an Object without inheriting from it.



      If you know any better way to achieve the same thing, please let me know.







      ruby-on-rails design-patterns soa






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 10:10









      Vivek TiwaryVivek Tiwary

      156




      156






















          1 Answer
          1






          active

          oldest

          votes


















          1














          It feels like you're thinking along the same lines as ActiveResource, which provides an ActiveRecord-like interface to objects across a REST interface.



          If you're intending to keep the two codebases entirely separate, then some form of API-based relationship is probably the way to go. One thing you do have to be careful with is how much network traffic you generate with this approach. If these two apps are going to be the only users of the API you build, you have an opportunity to build more customised endpoints based on your use cases that can deliver the data you need as efficiently as possible.






          share|improve this answer























          • what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

            – Vivek Tiwary
            Nov 13 '18 at 11:00












          • Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

            – Scott Matthewman
            Nov 13 '18 at 11:09










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278575%2fmodel-data-sharing-in-rails-using-http%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          It feels like you're thinking along the same lines as ActiveResource, which provides an ActiveRecord-like interface to objects across a REST interface.



          If you're intending to keep the two codebases entirely separate, then some form of API-based relationship is probably the way to go. One thing you do have to be careful with is how much network traffic you generate with this approach. If these two apps are going to be the only users of the API you build, you have an opportunity to build more customised endpoints based on your use cases that can deliver the data you need as efficiently as possible.






          share|improve this answer























          • what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

            – Vivek Tiwary
            Nov 13 '18 at 11:00












          • Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

            – Scott Matthewman
            Nov 13 '18 at 11:09















          1














          It feels like you're thinking along the same lines as ActiveResource, which provides an ActiveRecord-like interface to objects across a REST interface.



          If you're intending to keep the two codebases entirely separate, then some form of API-based relationship is probably the way to go. One thing you do have to be careful with is how much network traffic you generate with this approach. If these two apps are going to be the only users of the API you build, you have an opportunity to build more customised endpoints based on your use cases that can deliver the data you need as efficiently as possible.






          share|improve this answer























          • what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

            – Vivek Tiwary
            Nov 13 '18 at 11:00












          • Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

            – Scott Matthewman
            Nov 13 '18 at 11:09













          1












          1








          1







          It feels like you're thinking along the same lines as ActiveResource, which provides an ActiveRecord-like interface to objects across a REST interface.



          If you're intending to keep the two codebases entirely separate, then some form of API-based relationship is probably the way to go. One thing you do have to be careful with is how much network traffic you generate with this approach. If these two apps are going to be the only users of the API you build, you have an opportunity to build more customised endpoints based on your use cases that can deliver the data you need as efficiently as possible.






          share|improve this answer













          It feels like you're thinking along the same lines as ActiveResource, which provides an ActiveRecord-like interface to objects across a REST interface.



          If you're intending to keep the two codebases entirely separate, then some form of API-based relationship is probably the way to go. One thing you do have to be careful with is how much network traffic you generate with this approach. If these two apps are going to be the only users of the API you build, you have an opportunity to build more customised endpoints based on your use cases that can deliver the data you need as efficiently as possible.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 10:33









          Scott MatthewmanScott Matthewman

          1,217822




          1,217822












          • what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

            – Vivek Tiwary
            Nov 13 '18 at 11:00












          • Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

            – Scott Matthewman
            Nov 13 '18 at 11:09

















          • what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

            – Vivek Tiwary
            Nov 13 '18 at 11:00












          • Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

            – Scott Matthewman
            Nov 13 '18 at 11:09
















          what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

          – Vivek Tiwary
          Nov 13 '18 at 11:00






          what do you mean by you have an opportunity to build more customized endpoints based on your use cases that can deliver the data you need as efficiently as possible?

          – Vivek Tiwary
          Nov 13 '18 at 11:00














          Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

          – Scott Matthewman
          Nov 13 '18 at 11:09





          Basically that you only need to transfer the information between applications that they need to get the job done. If you're doing actions on one app that require lots of individual REST calls to the other, you might be able to replace that with a single API call that places a request, and gets a tailored response. It really depends on your what your apps are doing, but the key is that if both of them under your control, and no other apps are going to need to use the same API that they use to talk to each other, you have options beyond REST.

          – Scott Matthewman
          Nov 13 '18 at 11:09

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278575%2fmodel-data-sharing-in-rails-using-http%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3