Testing the APIs

Once we have created and run our application, now it’s time to check if the REST APIs are performing their tasks properly or not. To check this, open Postman application in your computer and let the spring application active on port no 8080. We have defined the controller mapping as “/products”, hence the API to access the products will be

localhost:8080/products

1. Create Operation

As of now, our database is empty and holds no record. Let’s send a POST request and insert a product details.

{
"name":"DSA Couse",
"qty":1,
"price":999
}

Output:

We can observe from the above picture that we made a POST request to the server and gave the data to insert into the database. The server responded with response code 200 and showed us the inserted record. We can also see that we didn’t provide the id attribute which is generated by the MongoDB.

2. Read Operation

We have inserted few more records in the database and now let’s use a GET request to get all the products details form the server.

We can see that we got all the records which are there in our database.

Now, let’s try requesting a single product using Id.

We have requested the details by using the Id of Web Dev Course and we got all details of this product.

3. Update Operation

Let’s suppose update the Web Dev Course‘s details and change it’s price to 799 and qty to 1. To do so we will be using PUT request.

And we can see that the required changes are made that means we have successfully updated the product details.

4. Delete Operation

Now let’s delete a record from the server. Suppose we want to delete the the App Dev Course, so make a Delete request to the server using it’s Id.

As there is no response set to the delete request we are not getting any output but the server response code is 200 OK, which means we have successfully deleted the product. Now to re-verify we can make a GET request to get all products details and see if App Dev Course is there or not.

We can see, we only have two records left and there is no App Dev Course in the database. We can also observe that the Web Dev Course present here is also of updated values. Thus, all the REST APIs for CRUD operations are usable and performing perfectly.



Creating REST APIs Using Spring WebFlux and MongoDB

Spring Boot is the most popular Java framework for building stand-alone Java-based applications quickly and with minimal configuration. WebFlux is a responsive operating system provided by the Spring framework for running non-blocking, asynchronous, and event-driven applications. On the other hand, MongoDB is a popular NoSQL database that is widely used for its flexibility and scalability. In this article, we are going to build REST APIs using Spring Boot WebFlux and MongoDB. Using an API call, we will perform a Create, Read, Update, and Delete (CRUD) operation.

Similar Reads

Steps to Implement CRUD Operation using MongoDB in Spring WebFlux

Below are the steps to implement CRUD REST API using the MongoDB database in Spring WebFlux....

Testing the APIs

Once we have created and run our application, now it’s time to check if the REST APIs are performing their tasks properly or not. To check this, open Postman application in your computer and let the spring application active on port no 8080. We have defined the controller mapping as “/products”, hence the API to access the products will be...