0

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 ??

Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
  • You can use spring-security to only allow authorized individuals to access v1 and v2 of your API (Like the user with ROLE_ADMIN). and have v3 be open to access by anyone. – Akash Jain Jun 28 '21 at 06:24
  • @AkashJain that's not what the OP wants -- that would give a 401 status. – tgdavies Jun 28 '21 at 06:28

1 Answers1

1

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);
}
Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
  • This could also be modeled with `501 (Not Implemented)` or `400 (Bad Request)`. It's a _bad request_ because the client doesn't know how to call the server properly. – Chris Martinez Jul 01 '21 at 15:59