Spring Boot lab (part 2): REST
The second part of this series on Spring Boot shows how to add a REST endpoint to a Spring Boot application.
What will be done here?
We will modify the application taken from part1 so that it exposes a REST endpoint. Besides, we add a test case for the endpoint.
Implementation
The REST controller
This controller is pretty simple. When the endpoint ‘/welcome’ is called, it will simply return a string.
The test case
The test case is annotated with WebMcvTest, which means that the application configuration is not fully loaded. Instead, only the configuration for this controller and similar components is applied.</br>
The test is probably not quite meaningful as it just tests if the HTTP status is 200, i. e. ok.
Another version of the test could even check, if the string ‘Welcome’ is returned.