I am trying to version my APIs and the approach I am following is by allowing the Accept
header.
@GetMapping("/api/version", produces = ["application/vnd.app.v1+json"])
fun versionOne(): Map<String, String>{
return mapOf("version" to "1")
}
@GetMapping("/api/version", produces = ["application/vnd.app.v2+json"])
fun versionTwo(): Map<String, String>{
return mapOf("version" to "2")
}
Now above works well. If the API consumer doesn't pass any accept header, then automatically version 2 is picked up based on the sequence of the code.
Now my API is already consumed and a few of them are passing Accept: application/json
and here my API fails. It returns an error, is there a way to have an or
match? If the Accept
header is empty or application/json
, return the latest version.