Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When an API\'s data structure does not fit well with an angular app, I am trying

ID: 647858 • Letter: W

Question

When an API's data structure does not fit well with an angular app, I am trying to determine the best-practice in my specific design and implementation for converting it to a usable structure.

I was doing this on an 'as needed' basis within the app controllers/directives, which quickly lead to spaghetti code.

Now I'm thinking this belongs in the service/factory which interacts with the API. Are there drawbacks or benefits to the Factory pattern over a more service oriented architecture when it comes to handling data structure conversion?

Explanation / Answer

Yours is a common-enough problem that the solution is has a name: an anticorruption layer. This is a layer that translates between an external API with an undesirable structure and the desired internal structure of your app. The idea is to limit the "corruption" of the undesired structure to as small a part of your code as possible.

The external API doesn't have to be bad in an absolute sense, just not ideally suited for your particular application. If you can think of a better API, by all means go for it. The earlier you do, the cleaner your code will be.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote