1.

Example of @DELETE rest endpoint?

Answer»

Below code structure represent the Rest Controller class developed using spring boot framework which use to ACT as Http Delete method.

IMPORT java.util.Map; // Below series of import is important package specially org.springframework package import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.practise.springboot.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<>();  // Below method responsible to handle the HTTP DELETE request, which will RECEIVE the Path   //variable {id } as a  parameter and responsible to delete  the database information according  // to the id parameter.   @RequestMapping(value = "/PRODUCTS/{id}", method = RequestMethod.DELETE)   public ResponseEntity<Object> delete(@PathVariable("id") String id) {      productRepo.remove(id);      return new ResponseEntity<>("Product is deleted successsfully", HttpStatus.OK);   } }


Discussion

No Comment Found