0

I'm working with the OOP MVC pattern of building a web app. For my current project, I have to tightly intergrate data from an external API into my backend (node). It's the first time I've done this.

My application sends, recieves, and polls for data from this API service.

At the moment I have:

  • an object that encapsulates the API calls.
  • an object that polls the API and updates my app's database.
  • mvc controllers that want to talk to my models and the API's data.

Some user actions include calls to this API. At the moment my controllers are making calls to the API handler directly and everything feels a bit messy and interdependant. I'd like to structure it in a way to minimise data syncronisation issues as well. Are there any standardised or good patterns of adding this kind of external API intergration into a ruby-on-rails style MVC pattern?

1 Answer 1

1

Although i have only slight experience with node, i'm going to approach this as a general way of doing things.

I have to tightly intergrate data from an external API into my backend (node).

I don't know the specifics but that's generally a bad idea.

Your application should dependend on it's own data models, controllers and views. If you integrate your application deeply with external models, you'll be a hostage of that external api lose control of your application.

In order to maximise decoupling i would do something like this:

|Your App| <-> |Proxy App| <-> |External API|

|Your App|

Contains the model views and controllers, the regular stuff. If you ever need something from external api, you should ask the |Proxy App| to send, receive and pool for data. |Your App| shouldn't change unless there's a real reson to do so.

|Proxy App|

It will make requests to the |External API| and retrive data from it. If the |External API| changes, only this |Proxy App| will change.

So, having this in mind you should have:

|Your App|

  • mvc controllers that want to talk to my models.
  • the controllers will make requests to the proxy app when they need external api data.

|Proxy App|

  • encapsulates the API calls.
  • polls the API and updates my app's database.

Some user actions include calls to this API.

In this case |Your App| would make a request to |Proxy App| and who will handle that request and handle the response.

Hope this gives you the insight you need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.