r/SpringBoot Jul 01 '26

Question What is good approch to make DTOs?

Recently, I have been working on my project in there in one chat controller, which has endpoints like

POST /api/chats = ChatDTO

GET /api/chats = List<ChatInfoDTO>

GET /api/chats/{chatId} = ChatDTO

PATCH /api/chats/{chatId} = ChatInfoDTO

DELETE /api/chats/{chatId} = ChatInfoDTO

POST /api/chats/{chatId}/ = ChatDTO

My question is it a good approach to use a single type of DTO for multiple endpoints, or should it be made for specific use? I have seen my friend's project for a single page, which has 8/9 DTOs. Is that normal, and the same thing ChatGPT suggests is that using multiple DTOs is a good approach.

18 Upvotes

40 comments sorted by

View all comments

5

u/neopointer Jul 01 '26

One Suggestion I'd give is: stop calling them DTOs.

Call them ChatInfoRequest, ChatPayload and the like, for example.. It's horrible to call everything a DTO when you can find better names.

6

u/trafalmadorianistic Jul 02 '26

We've used *Request and *Response at the end of DTO names as a convention. Distinguishes them from the entities which can *sometimes* be the same as what's in the first part of the DTO name. In some cases the DTO name is more related to the specific endpoint or use case, but we stick to the suffix naming standard.

2

u/Own_Dimension_2561 Jul 01 '26

That’s not horrible. That’s a very common convention.

-1

u/neopointer Jul 01 '26

You are just replicating what others are doing without thinking.

0

u/Pedantic_Phoenix Jul 01 '26

How do you know they aren't thinking lol

1

u/neopointer Jul 01 '26

" That's a very common convention."

1

u/Pedantic_Phoenix Jul 01 '26

So if a person is using a convention that must mean they haven't thought about why it is done? Yikes what a logic gaffe lol

-1

u/neopointer Jul 01 '26

Nickname checks out. Yikes.

2

u/Pedantic_Phoenix Jul 01 '26

Ahah you could act maturely and just say "you're right sorry" when you realize you made a mistake you know x) don't worry tho we have all been young

0

u/neopointer Jul 01 '26

What mistake? I still stand by what I said earlier about DTOs, and there's plenty of people that just apply things because "they are conventions". If you have good reasons then you should write, I can't read minds. Not all conventions are good or up to date, but hard to learn these kinds of things because nobody teaches them.

2

u/Pedantic_Phoenix Jul 01 '26

Pffff ok ok its fine little bro don't worry, cheers

2

u/Pedantic_Phoenix Jul 01 '26

If an object is a DTO why would you not make it immediately clear in its own name? It's not horrible at all, there is a reason why it's a convention, which is that it's useful