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.
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.
*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.
Read Operation:
The read operation is a GET request to return all of a collection's documents.
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.
*Delete Operation: *
The delete action makes use of the delete request. The controller implementation is shown below.
Further I used validations to this web application.
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.
1.First, click the ‘new’ button.
2.After that click on the ‘Get request’.
Fill in the form to create the Get Request
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:
Send a simple restful get request to the spring boot service using Postman.
We'd get the following result if we ran across the breakpoint.
Add http post api to codes.
Add this code to the controller:
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:
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
Ensure that the POST http method is selected.
Input the post url and headers.
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
Top comments (0)