Search code examples
javaangulartypescriptspring-bootdto

Keeping models between spring boot and angular application in sync. Alternatives?


In client-server applications with spring-boot and angular. Most resources I find explain how to expose REST endpoint from spring boot and consume it from angular with an http client.

Most of the time, communicating in JSON is preconized, maintaining DTOs (DataTransfertObject) in both angular and spring boot side.

I wonder if people with fullstack experience knows some alternative avoiding maintaining DTOs in both front and backend, maybe sharing models between the two ends of the application?


Solution

  • Swagger would be a good tool to use here.

    You can take a code-first approach which will generate a swagger spec from your Java controllers & TOs or a spec-first approach which will generate your Java controllers & TOs from a swagger spec.

    Either way, you can then use the swagger spec to generate a set of TypeScript interfaces for the client side.