How in Java (REST api) you can specify 2 resources located in the same path, so the execution depends on the version client had provided?

StackOverflow https://stackoverflow.com/questions/22153511

  •  19-10-2022
  •  | 
  •  

문제

Example:

@POST
@Path("/commonPath")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response getMethoV1(RequestDto1 reqDto) {
   //logic
}

@POST
@Path("/commonPath")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response getMethoV2(RequestDto2 reqDto) {
   //logic
}

How can this code be adjusted, so the clients who use app version 1 could go to getMethod1() and those who have switched to version 2 could use resource getMethod2()? And RequestDtos may or may not be the same class objects.

올바른 솔루션이 없습니다

다른 팁

Easiest way to version the API is including version number as part of the URI during the development.

/commonPath/v1.0
/commonPath/v1.1

Your code would then become like this

        @GET
        @Path("/commonPath/v1.0")
        @Consumes(MediaType.APPLICATION_XML)
        @Produces(MediaType.APPLICATION_XML)
        public Response getMethoV1(RequestDto1 reqDto) {
           //logic
        }

        @GET
        @Path("/commonPath/v1.1")
        @Consumes(MediaType.APPLICATION_XML)
        @Produces(MediaType.APPLICATION_XML)
        public Response getMethoV2(RequestDto2 reqDto) {
           //logic
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top