Questions Management – API Option Service – Build API delete option using Spring WebFlux

Check out the full series of Questions Management tutorial here.

In the previous tutorial, we prepared all the necessary configurations to be able to construct API delete option such as an object containing all the information of an Option; a CoreOptionService interface with the implementation CoreOptionServiceImpl is responsible for handling the Core Option Service; an OptionController defines the APIs for the API Option Service that will start with “/option” and information about the Core Option Service is configured in the application.properties file. Now, let’s build this API!

To build API delete option, I would first add a new deleteOption() method in the CoreOptionService interface:

The implementation of this method calls the Core Option Service in the CoreOptionServiceImpl class as follows:

As you can see, here I have used the WebClient object to connect to the Core Option Service and call the API delete option of this service with the URI “/option/{id}”.

Next, I’m going to add a method in OptionController that calls the deleteOption() method of CoreOptionService to expose a DELETE request “/option/{id}” as follows:

At this point, we have completed the API delete option for the API Option Service, let’s try it out.

Assuming the current in the database I have the following options:

Questions Management – API Option Service – Build API deletion option using Spring WebFlux

so If I delete option with id 5b871766f62c5604f6a6a8fb, the result will be as follows:

Questions Management – API Option Service – Build API deletion option using Spring WebFlux

Questions Management – API Option Service – Build API delete option using Spring WebFlux
Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
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.