英文:
Versioning through content negotiation in mvc
问题
我有两个使用相同请求路径和响应的 GET API,其中一个已经存在,另一个是新创建的。
@GET
@Path("/{id}/export")
public Response exportVersion1(@PathParam("id") String id, @QueryParam("format") final String format)
@GET
@Path("/{id}/export")
@Consumes({"application/vnd.com.abc.v2+json"})
public Response exportVersion2(@PathParam("id") String id, @QueryParam("format") final String format)
当我将内容类型设置为 application/vnd.com.abc.v2+json
时,我能够调用第二个 API,但如果不提供内容类型,那么也会调用第二个 API。
我想将第一个 API 设置为默认选项,并且不想对其进行更改或添加,因为它与客户端使用的 UI 相关联。我只能对第二个 API 进行更改,请提供任何建议。
英文:
I have two get API with the same request, path, and response out of which one already exists and the other one which is created new.
@GET
@Path("/{id}/export")
public Response exportVersion1(@PathParam("id") String id, @QueryParam("format") final String format)
@GET
@Path("/{id}/export")
@Consumes({"application/vnd.com.abc.v2+json"})
public Response exportVersion2(@PathParam("id") String id, @QueryParam("format") final String format)
On giving content type as application/vnd.com.abc.v2+json I am able to call the second API but if no content type is given, then also the second one gets called.
I want to make the first one as default and don't want to change/add to it as it is bound to UI used by the client. I can only make changes to the second API, please give any suggestions.
答案1
得分: 1
你可以设置默认内容类型。对于Spring 5,代码如下:
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_PLAIN);
}
英文:
You can set default content type. For spring 5 this will be:
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_PLAIN);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论