I have developed a stand-alone java application (java 8 + javafx) using the MVC pattern. Now I should start to develop the web app and , according to the MVC pattern, only the View should change. My problem is: I don't know how to link the Angular frontend with the Java backend of the stand-alone app. How do these parts communicate? How do the frontend invoke the controller's methods?

4 Answers

Asoub On

The most common way is to use REST.

Your backend needs to expose a REST API which will be used by the Angular to access/modify data.

If you're using Spring, you can use the @RestController to create your endpoints. IIRC, you can use the HttpClient class in Angular to call rest APIs.

You'll find many examples on the web.

kutsyk On

As I understood, you don't see how your Frontend application (Angular) lays down on MVC pattern.

It doesn't

You MVC pattern in the current case won't be fully implemented, as you will implement Model and Controllers but not View.

So you implement your controllers to return JSON results, not View, and you call those routes from your Frontend(Angular) application which is parallel to your Java application and should be started(hosted) separately or as static resources from your Java Backend.

avi.elkharrat On

Welcome to stackoverflow.

An Angular application is a Front-End web application. That means that it will execute in a web browser.

You cannot just plug-in an Angular app to a Java app.

What you need to do is:

  • on je Back-End side (Java 8 side): develop a REST server, i.e. a set of REST services that will recieve and process REST queries from the Front-End. Typically, people use Spring nowadays to wirte this kind of code (but there are other libs, frameworks...)

  • on the Front-End side (Angular): develop a REST client, i.e. a set of REST services that will emit queries and recieve the answers from the Back-End. Don't go looking too far: Angular comes with a full REST facility out of the box.

My recommandation at this point: Angular has a tutorial that will explain pretty well how to build client REST services. Start by doing this tutorial. If you need extra info, the documentation is pretty neet. And of course, for any complementary questions, SO is the place.

Tahmidur Rahman On

Develop a frontend using Angular. Develop rest api with Java to communicate with the Angular frontend. Can use spring to develop rest api. Angular can process json or xml data. A rest api endpoint can output as json/xml and take input as json/xml data.