Questions Management – API Question Service – Build API delete question using Spring WebFlux

Check out the full series of Questions Management tutorial here.

In the previous tutorial, we prepared all the necessary configurations to build API deletion question: an object containing all the information of a question CompositeQuestion including Question, Category and Option; a CompositeQuestionService interface with CompositeQuestionServiceImpl implementation is responsible for handling the Composite Question Service, an ApiQuestionController that defines the APIs for API Question Service will start with a “/question” and information about the Composite Question Service is configured in the application.properties file. Now, let’s build this API!

To build API delete question, first, I will add a new deleteQuestion() method in the CompositeQuestionService interface:

The implementation of this method in the CompositeQuestionServiceImpl class is as follows:

As you can see, here I have used the WebClient object to connect to the Composite Question Service and call the API deletion question with the “/question/{id}” URI.

Next, I’m going to add a new method in ApiQuestionController that calls the deleteQuestion() method of the CompositeQuestionService to expose a “/question/ {id}” request as follows:

At this point, we have completed the API deletion question for API Question Service, let’s test it out.

Assuming that our Questions Management application currently has the following questions:

Questions Management – API Question Service – Build API delete question using Spring WebFlux

then when you request to delete the question with id “5b68de7ce0d76908736648ea”, the result will be:

Questions Management – API Question Service – Build API delete question using Spring WebFlux

Questions Management – API Question Service – Build API delete question using Spring WebFlux
Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
0Share on Google+
Google+
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.