Home > Blockchain >  What is the purpose of returning JSON response in Spring?
What is the purpose of returning JSON response in Spring?

Time:07-23

Please explain why we need to return json responses in Spring. I understand how rest controller works, but I do not understand what I can do with that response.

CodePudding user response:

JSON is the industry standard for transporting marshaled objects between a service and the calling client. Sometimes XML is used, but it tends to be verbose and overly complicated whereas JSON is very simple, compact, and easy to understand. The receiving client can easily unmarshal the JSON response into an object it can more easily utilize.

CodePudding user response:

Let's say you have a web interface and we want to show the result of the queries made from the database. We are sending a GET request using axios with React. What kind of result should return to make it usable with javascript code? JSON of course. This is a common data format that we will use to communicate with the backend and frontend. This was just a small sample. As Wikipedia writes:

It is a common data format with various uses in electronic data exchange, including server-side web applications.

  • Related