All jobs / Backend developer / API Development
Backend developer interview question · 0–1 years
The interviewer asks: “Do you return the database entity as JSON?” Strongest answer?
The strongest answer
No. I return a DTO I control. Entities hide lazy loads, circular references, and columns the client must not see.
Why it works
Exactly. The persistence model is not the HTTP contract. Map it. That's how you avoid over-posting and surprise columns.
What a good answer covers
- API returns DTOs, not entities.
- Map explicitly at the edge.
- Don't share one type with the database.
- Never serialise secrets or hashes.
Answers that fall short
- Close, but not the strongest: Return the entity and [JsonIgnore] the navigation properties.
JsonIgnore is a bandage that breaks when someone adds a navigation. A DTO is the list of fields you meant to ship. - Weak: One shared model for the database, the API and the UI.
One model means a column rename is a breaking API change and a UI change in the same commit. That's coupling, not DRY. - Red flag: Include password hashes and refresh tokens on the user entity because the admin UI needs them.
Hashes and tokens in JSON are credential theft waiting on a log or a XSS bug. Admin UIs get their own, narrower DTO — still never the hash.
Who gets asked this
More API Development questions
- The interviewer asks: “A handler throws. What does the client see?” Strongest answer?
- The interviewer asks: “How do you paginate a list endpoint?” Strongest answer?
- The interviewer asks: “Where do you validate input?” Strongest answer?
- The interviewer asks: “PUT versus PATCH?” Strongest answer?
- The interviewer asks: “How should API errors look to clients?” Strongest answer?
- The interviewer asks: “How do you version a public JSON API?” Strongest answer?
- When would you pick gRPC over a JSON REST API, and what do you give up?
- Your OpenAPI document lists every path and method and nothing else. A partner team says integrating still…