Clean Architecture with REST api

977 views
Skip to first unread message

Souji Tendo

unread,
Dec 30, 2019, 10:23:46 PM12/30/19
to Clean Code Discussion
How can I return JSON response from presenter, in this diagram I don't know how presenter can present the ResponseModel.
Should presenter return another model (ex: RestModel) or just return the ResponseModel from the Interactor and let Controller handle it.

Image result for clean architecture

Łukasz Duda

unread,
Dec 31, 2019, 4:06:40 AM12/31/19
to Clean Code Discussion
Hi,
I suppose there is no one correct answer.
There are situations in which you prefer to return the response model, in others you prefer to call action and cause some behavior. For instance In case of integration with different system I often choose to return data structure.

The diagram shows that the interactor calls methods on the presenter, who probably prepares the view model based on the arguments passed in calls, e.g. based on the response model.

Below is an example of a controller that gets a view model from the presenter.

https://github.com/cleancoders/CleanCodeCaseStudy/blob/master/src/cleancoderscom/usecases/codecastSummaries/CodecastSummariesController.java
https://github.com/cleancoders/CleanCodeCaseStudy/blob/master/src/cleancoderscom/usecases/codecastSummaries/CodecastSummariesPresenter.java

I can imagine service, where controler doesn't prepare view and returns simple data structure, some kind of response model. It could be JSON. I got the feeling, that REST is more about resources. I'm not sure, that trying to map behaviors to resources pays of.

In another example I was trying to understand the differense between returning data structure or calling responder actions.

https://github.com/lukasz-duda/Responder

Tobias Strandberg

unread,
Nov 4, 2020, 3:42:44 AM11/4/20
to Clean Code Discussion
Hi,
this is something that took me a long time to figure out. If you're still interested, please see this article that I've written about Clean Architecture that explains this.
Reply all
Reply to author
Forward
0 new messages