DEV Community

Cover image for How to create simple rest apis with springboot

How to create simple rest apis with springboot

Aditya Sridhar on November 05, 2018

This post was originally published in adityasridhar.com As a part of this article you will be building 2 simple REST apis Using Springboot. This...
Collapse
 
martin profile image
Martin Beentjes

Looks good, I would recommend updating Spring Boot to 2.1.0. Besides that, don't use 'Test' in such tutorials. Keep them realistic and use something like "getAll()" or something.

Why don't you use ResponseEntity<>?

And another good improvement would be to explain how a request flows from the browser of the user through the (Rest)Controller to the Service and into the Repository if needed.

Collapse
 
adityasridhar profile image
Aditya Sridhar

Thank you for the feedback :)

Will use proper naming conventions in the next one :D

I could have used response entity as well. Maybe will use that in the next article.

Planning to write one more article for the flow from controller to service to repository. That's the reason I did not include it here. Wanted to separate them out since having them in one article makes the article long and readers may feel its too much information in one article.

Collapse
 
martin profile image
Martin Beentjes

I prefer to use ResponseEntity because it is Spring itself as the tutorial focuses on Spring.

Good luck!

Collapse
 
stealthmusic profile image
Jan Wedel

Always good to see some Java love around here 😊

Two recommendations:

  • Use @GetMapping and @PostMapping for better readability
  • use Lombok getters/setter for the entities

See dev.to/stealthmusic/modern-java-de...
😎

Collapse
 
adityasridhar profile image
Aditya Sridhar • Edited

Thank you for the suggestions :)

Will read the article :)

Collapse
 
stealthmusic profile image
Jan Wedel

BTW, Lombok is also available at start.spring.io ! Just type it in the dependencies search box.

Thread Thread
 
adityasridhar profile image
Aditya Sridhar

sure. thanks for letting me know :)

Collapse
 
cadonau profile image
Markus Cadonau

Great timing. I was just experimenting with Spring Boot.
Any tips on connecting a database to store and retrieve model objects?

Collapse
 
youssefsab profile image
Youssef Sabry

If you need a fully fledged ORM, you can use Spring Data JPA with Hibernate which is really easy to get started quickly and works very well with Spring Boot. I use a library called JOOQ (Java Object Oriented Query) which allows you to write type safe SQL and provides you with code generation features. It also gives you basic CRUD. Also I use flyway for migrations.

Collapse
 
arj profile image
arj

Just have a look at the official guides.
spring.io/guides/

There is one for relational database access (spring.io/guides/gs/relational-dat...) and for others as well.

Collapse
 
adityasridhar profile image
Aditya Sridhar • Edited

Hibernate is a good option.

You could also use spring JDBC. Explore both and check :)

Collapse
 
biros profile image
Boris Jamot ✊ /

Nice post, and glad to see a post about SpringBoot!

Collapse
 
adityasridhar profile image
Aditya Sridhar

Thank you