javaspring-bootspring-mvcspring-restcontrollerapi-versioning

How to Invalidate all the requests for Expired API versions in URI Path with response like 410:Gone in Java?


If I have a new version of API implemented using API versioning of the form /api/v3/example/resource, and I wish to Reject request of form /api/v1/**, /api/v2/** etc. for all the requests having this structure, how can i do that ??


Solution

  • You could add the following request handling method to your controller with mappings for all your deprecated paths:

    @RequestMapping(value = {"/api/v1/**", "/api/v2/**"})
    public ResponseEntity<?> deprecatedVersions() {
        return new ResponseEntity<>(HttpStatus.GONE);
    }