This is a simple demonstration of a Spring Boot webhook based off this YouTube tutorial. I cleaned up some bad practices from the tutorial.
- I used
H2 Database
instead of aMySQL
driver. - In the tutorial,
@Controller
was used. I replaced it with@RestController
as a view was not provided or necessary. @RequestBody
is not required for each method when you use@RestController
.- In fact, most conventions in the tutorial follow a typical
SpringMVC
implementation. Spring Initializr
has stopped including a maven jar. I always excluded it from my repositories on GitHub.- In
VSCode
, you can have problems when you add another application to an exisiting Java workspace. It is best torestart
after adding another application to your folder. There needs to be only folder in the Java workplace. It doesn't matter if that one folder contains multiple applications. - The
students
array was initialized inside the controller method. This is problematic, as the array of students will be overwritten everytime the method is accessed. It is better to initialize the ArrayList inside the model entity. - Multiple ways to use
optional
in the controller. By utilizingorElseThrow
and aSchoolDataNotFoundException
, I was able to avoid usingoptional
directly. - I replaced
RestTemplate
with newerRestClient
. The change actually increases LOC. Both are still synchronous and blocking.
- Need to investigate best way to test a webhook.
- Idempotence for webhooks is an area I could research.
- Baeldung - spring boot h2 database
- Geeks for Geeks - difference between controller and rest controller annotation in spring
- Stack Overflow - how to put prefix when create a custom id generator in java spring boot
- Stack Overflow - how to avoid visual studio code warning myfile java is a non project file
- dzone - replace your rest template
- Baeldung - spring webclient resttemplate
- Spring Docs - rest clients
- Blog - think twice before using onetomany
- YouTube - Java Optionals, a Practical Walkthrough - Java Programming
- Blog - null checking done right with optionals