Let's Build an API together - Part 9
Now that we have defined our API in RAML and generated the Spring MVC controllers, etc. it is implementation time. Before we write our code, we should consider if we go with a classic 3 tier design or skip some of them.
When our application is tiny and does not have much logic in it, we could skip the service layer and directly work with the Spring Data repositories in the Spring MVC controllers.
However, if we have business logic, it’s better to separate that in a service layer. It makes it easier to distinguish between code implementing business logic and code for talking with the outside world aka API.
As we use the generated code, we must plug in ours anyways with class(es) implementing TaskIdController and TaskController. It’s not exactly a service layer because it uses the model of the API, but for our basic version it is good enough, and we’ll settle with a single service class TaskService implementing both interfaces.
When we enhance the API later, we probably have to refactor here and should consider this for any planning or estimates.
Want content like this in your inbox each workday? No BS, spam or tricks... just useful content: