Skip to content
Advertisement

Return success from api as true or false om Spring REST API

I am pretty new to Springboot. How can I configure my Springboot API to return the JSON response below from my login or register endpoints?. How I can return true – successful response? And also for example if there is a code exception into code processing how can I return false as the success JSON response?

JavaScript

What I have so far: My login API

JavaScript

My Signup API:

JavaScript

MessageResponse class

JavaScript

Advertisement

Answer

you didn’t post the code for MessageResponse, so if it’s your class you can add the boolean field to it and the ResponseEntity<?> wrapper can wrap this object that has 2 fields. another option is to use @ResponseBody annotation instead of ResponseEntity. please read more Here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement