Menu

The API Finally Answers Back — Building the REST Layer and One Handler for Every Error
📰

The API Finally Answers Back — Building the REST Layer and One Handler for Every Error

DEV Community: java·Rahkel Pekins·about 9 hours ago
#Q5cKw0qZ
#devtojava#devto#dev#tests#test
Reading 0:00
15s threshold

In Part 1 I set out to turn a legacy Java library app into a peer-to-peer platform. In Part 2 I made the persistence real — PostgreSQL, Flyway, tests on the real engine. But the app still had a problem: it had a solid service layer and a real database, and nothing a client could actually call.

Phase 2 fixed that. And I should be honest about where I started: I had never worked with Spring controllers before. I didn't learn controllers by implementing four of them at once. I learned one — the Catalog controller, done properly, as a guide example — and then generalized the pattern to the rest.

The design decision first: entities never cross the wire

Before any controller existed, one rule was settled: controllers return thin response records, never JPA entities. The app runs with open-in-view=false and the associations on BookCopy are LAZY, so returning an entity would either serialize a lazy proxy or blow up trying.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.