Author: techfox9

Basic REST web service example ..

Friday, May 8th, 2015 @ 1:25 am


@Controller // --> Declare a Spring MVC Controller

@RequestMapping("/computer") // --> Map an URI with a controller or a method

@PathVariable // --> Read a variable in an Uri and assign this value to a java variable

@RequestBody // --> Declare a Pojo class to map the http request body  

@ResponseBody // --> Declare a Pojo class to generate Json content to return to the http client

// Declaration as this class as a controller

// Declaration that this controller handles requests on uri */computer

public class ComputerController {
  // Stores computers
  private static final ComputerStorage computerStorage = new ComputerStorage();
  // Declare a method that handle all GET request on */computer
  @RequestMapping(method = RequestMethod.GET)

  // Return a list of computer to the http client
  @ResponseBody public List<Computer> getComputers() {
   return computerStorage.getAll();

Java, REST, Web, WebServices


Comments are closed.