Home » Java » java – REST API – Using a POST to read table, then send a JSON payload and receiving a response from this-Exceptionshub

java – REST API – Using a POST to read table, then send a JSON payload and receiving a response from this-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Whats the best approach to use a POST method in a REST API in order to read fields from a table and then eventually convert these fields into a json payload, which will then be sent to a server expecting a response e.g. 204 if they are happy with it.

I was thinking how I could start this approach in the controller, how I would handle this 204 response, at the minute I have this:

@RequestMapping(value = "/send", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
    public void readTables() throws Exception{

    //call a stored procedure to read tables and convert to JSON

   }

Of course there is a lot more to it, but is the RequestMethod.POST the best approach for reading tables and then sending this in one request? Or are there more steps to this within the Controller?

How to&Answers: