I'm working on a project where the UI is built with React Js. The communications with backend micro services (spring boot) go thru node / express server. The react app's using Axios HTTP client library .
The react does not directly call micro-services' rest api endpoints, but calls the api endpoint of the express server and the the express calls the micro services's endpoints.
communication: UI(using Axios) --> express server --> REST endpoint. I am curious why the react app does not directly call the backend api using the Axios and it has to go thru the node / express server.
is this an ideal design of client-server application or might there be other valid reasons for this. I would really appreciate and many thanks in advance if any explanation / if anyone can shade some light on this. Thanks! enter image description here I have also attached the screenshot of the folder structure. src/client - contains react code and src/server - contains nodejs code that communicates with the micro services endpoints .
I tried to trace the call from the front end to express to backend micro-services, but not quiet 10 0 % clear about the client-sever communications.
CodePudding user response:
For the project you're working on, it might go through the express server for some type of data transformation or applying some custom headers. And then express server makes the call to the Spring Boot application.
Tough to know what it does without actually seeing the code. In my current application, it goes to our Spring Boot application and then forwards the request to our Lambda microservices. We use the spring boot application to apply custom headers and some other miscellaneous things.