1.

Example of @Get endpoint?

Answer»

Below code structure represent the Rest Controller class developed using spring boot FRAMEWORK which use to act as Http Get method.

// Below series of import is important package specially org.springframework package. import java.util.HASHMAP; import java.util.Map; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.practise.springboot.model.Product; // Need to mention the RestController so that it will behave as rest end point. @RestController public class ProductServiceController {   private static Map<String, Product> productRepo = NEW HashMap<>();   static {      Product honey = new Product();      honey.setId("1");      honey.setName("Honey");      productRepo.put(honey.getId(), honey);      Product almond = new Product();      almond.setId("2");      almond.setName("Almond");      productRepo.put(almond.getId(), almond);   } // Below method act as a GET method, which is responsible to receive the HTTP GET call and return back the Product details as a RESPONSE along with the HTTP Status OK.   @RequestMapping(value = "/products",  method = RequestMethod.GET)   public ResponseEntity<Object> getProduct() {      return new ResponseEntity<>(productRepo.values(), HttpStatus.OK);   } }


Discussion

No Comment Found