How to connect frontend and backend? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to connect frontend and backend?

How front and backend communicate with each other? Considering I have REST API on Java Spring and frontend on JS.

15th Feb 2020, 6:45 PM
Ilja Veselov
Ilja Veselov - avatar
11 Answers
+ 5
You map the Controller to an URL and fetch from that URL. In Spring: Annotate @RestController and some (sub)annotation of @RequestMapping(value="myUrl") define the method (put, get, whatever). Alternatively, you can annotate with the dedicated subannotations: @PutRequest etc. On the frontend you can use the fetch method. That's all, basically.
15th Feb 2020, 7:45 PM
Tashi N
Tashi N - avatar
+ 2
Yeah, so many possibilities ;) Decision making can be hard. Maybe it's best if you read some how-tos of different providers and try to make a decision afterwards.
16th Feb 2020, 10:02 AM
Tashi N
Tashi N - avatar
+ 1
In production there will be jar or war file for backend. What will be for frontend - HTML, JS, css? Should front be running on different port/server?
15th Feb 2020, 10:17 PM
Ilja Veselov
Ilja Veselov - avatar
+ 1
The frontend will be a website with html, css, js as you mentioned created with or without frameworks like angular, vue, react, whatever you prefer. You can run frontend/backend on different ports for development but if you want to publish your website it's probably best to work with subdomains for frontend and backend. You'll find configuration instructions on your webhoster / provider websites.
16th Feb 2020, 9:43 AM
Tashi N
Tashi N - avatar
+ 1
Geoffrey L Sorry for the late reply, I'm just back from vacation ^^ From what I understand nginx correpsonds to the 'A' of the lamp environment, the web server. There are many other environments / predefined configs you can use to achieve the same, xampp is one I work with at home. Many providers advertise supporting nginx or other server solutions, as mentioned before it's hard to recommend one particular solution for me at least.
24th Feb 2020, 5:35 PM
Tashi N
Tashi N - avatar
+ 1
Tashi N no worry, hope you had good holidays :) I just see nginx popup everywhere in tutorials. I don't see why use nginx when a traditional LAMP is working as a charm. So for the moment I stay with the old school version :D
25th Feb 2020, 1:33 PM
Geoffrey L
Geoffrey L - avatar
15th Feb 2020, 6:54 PM
BroFar
BroFar - avatar
0
How to achieve that? With NGIX?
16th Feb 2020, 9:55 AM
Ilja Veselov
Ilja Veselov - avatar
0
Yeah, nginx or other :)
16th Feb 2020, 9:59 AM
Tashi N
Tashi N - avatar
0
Sorry too many silly questions in my head just trying to put the puzzle together
16th Feb 2020, 10:00 AM
Ilja Veselov
Ilja Veselov - avatar
0
Tashi N Ilja Veselov Based on this topic, which I was looking for, I would like to know what is the purpose of nginx ? Isn't the same to build a lamp environment to run a website ? Or they are totally differents technologies ?
19th Feb 2020, 7:19 AM
Geoffrey L
Geoffrey L - avatar