lundi 22 février 2021

Are Ports and Adapters supposed to abstract away the HTTP stack?

I am concerned about overengineering my code when thinking about Ports and Adapters architecture.

Two very common examples of the system contacting with the outside world are my HTTP stack and local filesystem. These are clear situations when the app is reaching out to the outside world, and testing will require certain amount of control and/or mocking.

My first though was: "Maybe I should have a central service or singleton and make sure any HTTP call goes through it"

For testing it would be amazing because I could force any test to crash if an unexpected call to the outside world is done without a mock or at least explicit concert by the developer. This also standardizes a single way to mock HTTP calls.

On the other side it feels like I am reinventing the wheel. I am a Javascript developer and the native library is not so good. Most people use a third party library which will spread as a dependency throughout the project.

My current approach is kind of re-inventing the wheel. I do create the abstraction layer (a service singleton) but keep it light using a third party library. The goal is trying to "contain" the spread of 3rd party library code over the project using a thin self made facade. Obviously things with a larger scope are an exception. For example abstracting away database access tends to cause more pain than glory.

Are self made abstractions for HTTP and local file system access a clear example of Ports/Adapters or just overengineering?

Aucun commentaire:

Enregistrer un commentaire