Search code examples
springrestspring-mvcrequest

REST and spring-mvc


Since REST based controller methods only return objects ( not views ) to the client based on the request, how can I show view to my user ? Or maybe better question what is a good way to combine spring-mvc web app with REST, so my user always get the answer, not in just ( for example ) JSON format, but also with the view ?

So far as I understood, REST based controller would be perfectly fitting to the mobile app ( for example twitter ), where views are handled inside the app and the only thing server has to worry about is to pass the right object to the right request. But what about the web app ?

I might be wrong in several things ( correct me if I am ), since I am trying to understand REST and I am still learning.


Solution

  • To simplify things - you basically have two options: 1) Build Spring MVC application. 2) Build REST backend application.

    In case of first option - within your application you will have both backend and frontend (MVC part).

    In case of second option you build only backend application and expose it through REST API. In most cases, you will need to build another application - REST client for your application. This is more flexible application because it gives you opportunity to access your backend application from various clients - for example, you can have Android, IOS applications, you can have web application implemented using Angular etc...

    Please note, that thins are not so simple, you can within one application have both REST backend and REST client etc... This is just very very simplified in order that you get some general picture. Hope this clarified a little things.