0

I am trying to invoke REST APIs in the controller layer using command line inputs from the user using a Spring Boot application. I am aware of CommandLineRunner interface. But according to my knowledge it can be used to run some code which needs to be run at the start of the application for once. But for my case when ever user input some command line values different REST APIs written in the controller layer should be invoked. Is this possible in a Spring Boot application?

eg -

user input - add 2 3

add 2 3 command should invoke the following api in the controller layer

controller layer

@RequestMapping("/add")
public int addNumber(@RequestBody SomeEntity entityObj) {
//
}
1
  • Why not just write a command-line application using Boot in that case instead of forcing it into some REST API? Commented Aug 1, 2021 at 5:42

2 Answers 2

1

i think you should use RestTemplate request the /add in CommandLineRunner

Sign up to request clarification or add additional context in comments.

Comments

-1

you just need to use curl on the command line to invoke a rest api

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.