2

I want to create API call by passing string value but without returning output.

Inside API method, only updating the value to database.

How to create API @postmapping(value = "endpoint") in this case

3
  • You can try @RequestMapping(value="endpoint", method=RequestMethod.POST) Commented May 14, 2018 at 5:59
  • instead of using @RequestMapping(value="endpoint", method=RequestMethod.POST) , we can use @PostMapping(value="endpoint) Commented May 14, 2018 at 6:02
  • Yes you can but without returning anything how can you be sure whether the transaction is successful or not. Commented May 14, 2018 at 6:05

2 Answers 2

1

Why do you not want to return anything? You should return at least true to notify the caller that the transaction was successful.

@PostMapping("/endpoint") public boolean updateSomeData(String value) { boolean result = someService.updateSomething(value); return result; } 

If you still do not want to return anything, you can simply change return type of the method to void as follows

@PostMapping("/endpoint") public void updateSomeData(String value) { someService.updateSomething(value); } 
Sign up to request clarification or add additional context in comments.

5 Comments

Okay. But i'm passing string parameters how can i declare it ?
I just put input type of Object because I don't know about your input.
one parameter updateSomeData(@RequestParam String value)
Then you can use, @PostMapping("/endpoint") public void updateSomeData(String value) { someService.updateSomething(value); }
@VanithaV I updated my answer. You can simply use String value. You can use or emit @RequestParam
0

If you want to pass string as pathvariable like,

http://your_host:your_port/your_projectName/endpoint/string_value

you can use below code

@PostMapping(value="/endpoint/{string_value}") public void update(@PathVariable("string_value") String string_value){ //update operation }

If you want to pass string as requestvariable like,

http://your_host:your_port/your_projectName/endpoint?string_value=somevalue

you can use below code

@PostMapping(value="/endpoint") public void update(@RequestParam("string_value") String string_value){ //update operation }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.