Tags | spring-boot rest-api mvc annotations |
Hard Prerequisites | |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. | |
|
We are going to focus on creating a REST api that will serve as an end point to our spring boot java application.
Continuing with PROJECT: Intro to spring boot project - Part 1 for the User we are going to expose a REST endpoint to the application.
Step 1
Create a Controller Class based on the spring MVC infrastructure. This will be used to expose the endpoint.
package controller;
public class UserController {
}
Step 2
Do the following in the UserController.
1 - Implement an end point to add a user
// returns string "[Name] added"
2 - Implement an end point to GET a user, should returns the user name
// returns string "Hello [Name]"
3 - Implement an end point to REMOEVE a user, should return that
// returns string "[Name] removed"
Example
@PutMapping
public ResponseEntity<String> update(@RequestBody Customer customer)
{
// ... ResponseEntity
}
Step 3
Make sure your rest Api layer is well tested
Side Notes
Happy Coding…