REST SERVICE using spring boot application example

This post explains a REST service implementation using springboot.

A brief about springboot:

Spring boot is a powerful framework that enables to develop applications quickly,removes hassles of maintaining configurations in XML’s,removes unnecessary boiler plate codes and abstracts wiring of different modules and its dependencies.In 2020 , this is one of the most sought after skills which every developer should know.Lets look at a simple spring boot application example and how easy it is to implement it.

Topics covered as part of this tutorial:

  • Expose a spring boot application as a REST service
  • Handle POST requests in spring boot
  • Implement business logic to handle incoming request

spring boot application example use case:

This spring boot application example takes inputs in forms of JSON as part of POST requests from clients.The application evaluates patient symptoms and data to check the likelihood of having COVID .

Parts of the application:

The application basically has 3 parts to it.

  1. REST controller : The class CovidCheckController is an implementation of REST controller. Its job is to accept inputs from the client which can be a web browser,Postman,etc . Controllers will figure out to whom it needs to route the requests to.
  2. Model : Classes in the package ‘com.ppk.covidcheck.model’ represents the patient domain. This patient domain is a set of POJO classes which represents the properties of a patient.
  3. Service : Classes in the package ‘com.ppk.covidcheck.service’ represent the service layer of this application. These classes handle the business logic.

Now lets check each part of this application.

flow of requests from clients to springboot

REST Controller:

As mentioned earlier , controllers are responsible to handle the incoming REST requests to a spring boot application. Notice the annotations @RestController , @Autowired and @PostMapping.

Model package:

This package represents the patient domain. There will be POJO classes describing patient behaviour and characteristics.

Every patient will have firstName,lastName,age and symptoms.

The symptoms is defined in another pojo Symptomps.java .

Did you notice that there are no getters and setters in the model classes?

Yes , the getters and setters are boiler plate codes which makes our code look a little ugly and clumsy . I have used Lombok to get it auto generated for me by using @Getter and @Setter annotations.

Service package:

Service package has classes which contains business logic of your application.In this class , I have written a simple logic to consume a patient object, check symptoms and return a Result object.You can use functional interfaces in java8 to handle business logic.

Testing the app:

I am using postman client to post json request to my application.Below are sample request and responses from the application.

End point URL :

http://localhost:8080/check

Sample request

Sample response

Application dependencies:

Since this is configured as a Maven project , the application dependencies are specified in pom.xml.

Code repository:

You can clone this spring boot application example code from github using this url:

https://github.com/pramodpk89/covid-check.git

You may also like...

11 Responses

  1. turkce says:

    Hey there just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Firefox. Cynthia Griffin Selima

  2. turkce says:

    I was studying some of your blog posts on this internet site and I conceive this web site is very instructive! Retain posting . Lin Brucie Ion

  3. yabanci says:

    Everything is very open with a clear clarification of the challenges. Murielle Brody Gayleen

  4. sikis izle says:

    Hi friends, its wonderful article regarding tutoringand completely defined, keep itt up all the time. Koral Jonathan Blase

  5. download says:

    You made some decent points there. I did a search on the issue and found most persons will go along with with your site. Yolanda Brantley Tjader

  6. yify says:

    Fastidious response in return of this query with real arguments and telling everything concerning that. Olympie Kimball Parlin

  7. web-dl says:

    I am actually grateful to the owner of this site who has shared this impressive article at here. Lisha Gib Harshman

  8. download says:

    There is evidently a bundle to identify about this. I suppose you made various good points in features also. Zonda Booth Penelope

  9. ucretsiz says:

    You completed a number of good points there. I did a search on the theme and found a good number of persons will agree with your blog. Bonnie Alan Vowel

  10. I reckon something truly special in this website.

  11. erotik says:

    Utterly pent written content , regards for entropy. Mala Conrado Nial

Leave a Reply

Your email address will not be published.