Wrapper modules can lead to better APIs

Wrapper modules can lead to better APIs

Learn how wrapper modules can help you design better APIs for your web apps.

In the article, I share a recent simple example that prompted the idea but I think it scales to larger more complicated scenarios as well.

An aside

In writing the article I also came across the concept of cohesion.

Cohesion refers to the degree to which the elements inside a module belong together.

This made me think about the pattern I see in many Elm web apps where it’s structured with the files Model.elm, Msg.elm, Update.elm, Views.elm, and Types.elm. Using the concept of cohesion we see that these modules have low cohesion which then leads to high coupling (a related concept) between the modules. Overall, it leads to a less maintainable, less testable and less scalable solution.

Whereas, the approach that Evan shares in The life of a file gives you highly cohesive modules which leads to looser coupling. Overall, you end up with a better application architecture that can be easier to maintain, easier to test and more scalable.

Anyway, I just thought it was an interesting way to look at it.


Excellent write up! We use this approach at work all the time, even with our own internal API requests.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.