2 Rest Services - shijazi88/springboot GitHub Wiki

Example 1 (Create Get, Post, Put, Delete Request using @Controller and @ResponseBody) Steps:

  1. Create project using STS or Spring Initializr
  2. Add Web Dependency in pom.xml
  3. Create Domain Class (i.e. User)
  4. Create UserController class
  5. Add @Controller annotation to UserController class
  6. Add @RequestMapping annotation to UserController class @RequestMapping(value="api")
  7. Define static List users variable to simulate database and add 2 users to the list
  8. Create new method to return all users in static list (getAllUsers)
  9. Add @RequestMapping(value="users", method=RequestMethod.GET)
  10. Run the application and call this URL http://localhost:8080/api/users