DEV Community

Kithmini
Kithmini

Posted on

Library Book Management Web Application

Overview of My Submission

About the web app (functionalities and flow)

  • This is a small web application for a library. The main goal of this web application is to allow users to add/view books and organize them into a table. The data can then be updated and deleted as needed.

Used technologies/languages and reasons

To create this web application, I used spring boot with the mongo DB. As a client, to test the web application we used POSTMAN.

Image description

In the very first I went to start.spring.io, which is a spring initializer. In there I had to enter the relevant details of the project, which programming language I used to implement this, Spring Boot version likewise .Then I havd to generate this file. This is downloading as a zip file. After that I had to open it using Eclipse.

Image description

*Testing and Results with explaining CRUD operations *

•CRUD operations have been viewed in computer programming as the four core functions of persistent storage: creation, read, update, and delete (CRUD).

•For testing, I utilized Postman, which is more versatile and allows us to test all endpoints.

Create Operation:

The create operation is a POST request that takes a BookLibrary model object as an input and saves it to Mongo DB using the repository's save() method. It returns the saved instance, which will have the unique id.

Image description

Image description

Read Operation:

The read operation is a GET request to return all of a collection's documents.

Image description

Update Operation:

The update operation makes use of a PUT request, accepts book Id as a path variable, and utilizes the same save method (). Because the id is contained in the model object, it will be updated in the database in this scenario.

Image description

*Delete Operation: *

The delete action makes use of the delete request. The controller implementation is shown below.

Image description

Further I used validations to this web application.

Image description

Image description

Image description

Guidelines to test the app

Open the main application file and run it as a Java program to launch the Spring Boot application. The message appears in the console after the application runs correctly, as illustrated below. Now open the browser and type http://localhost:8080 into the address bar.

Open postman and click the ‘create’ button.

Image description

1.First, click the ‘new’ button.
2.After that click on the ‘Get request’.

Fill in the form to create the Get Request

Image description

Fill in the request name and store it to a collection; if one doesn't exist, make one.

We'd get an empty postman request now:

Image description

Send a simple restful get request to the spring boot service using Postman.

Image description

We'd get the following result if we ran across the breakpoint.

Add http post api to codes.

Add this code to the controller:

Image description

It contains two features:

1.It has a new endpoint named ‘/book’ which accepts an json object and call the service to save it
2.It has a new endpoint named ‘/book/{id}’ which accepts an id and return the specified book object as json.

Add this code to the service:

Image description

To save and query the Book object, it simply uses Spring data JPA.

Test the post api with postman

Create a new http request in postman

Image description

Ensure that the POST http method is selected.

Input the post url and headers.

Image description

The following http headers are required by the Spring Boot restful post api:

1.Content Type -application/json
2.Accept- application/json

It signifies that the server expects the client to send the item in json format.

Input the body of the http post Instead of using the http url to pass the request body, the http post protocol uses the http body to do so.

If we don't want to manually construct the json string, go to (localhost:8080/BookLibrary/Book/1) to acquire a json template for the Book class.

Submission Category:

Own Adventure

Link to Code

GitHub logo kithminiii / MongoAtlas-Hackathon

MongoDB Atlas Hackathon of Dev.to 2022

Top comments (0)