4
我有一个返回User
对象泽西2.18 API端点。我的利益相关者需要API来生成WADL文件,该文件不仅反映API路径,还反映返回的对象类型。
这是由新泽西覆盖开箱即截至2015年,通过以下端点定义:
@GET
@Path("/")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public User getExampleUser() {
User exampleUser = new User();
return exampleUser;
}
球衣生成的结果WADL文件中正确包含端点,以及返回类型:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
<doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.18 2015-06-05 02:28:21"/>
<doc xmlns:jersey="http://jersey.java.net/" jersey:hint="This is simplified WADL with user and core resources only. To get full WADL with extended resources use the query parameter detail. Link: http://localhost:8080/example/api/v3/application.wadl?detail=true"/>
<grammars>
<include href="application.wadl/xsd0.xsd">
<doc title="Generated" xml:lang="en"/>
</include>
</grammars>
<resources base="http://localhost:8080/example/api/v3/">
<resource path="/">
<method id="getExampleUser" name="GET">
<request>
</request>
<response>
<ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="user" mediaType="application/json"/>
<ns2:representation xmlns:ns2="http://wadl.dev.java.net/2009/02" xmlns="" element="user" mediaType="application/xml"/>
</response>
</method>
</resource>
</resources>
</application>
但大多数的州界似乎有端点返回一个更通用Response
对象,它允许所有直至并包括E-TAG caching,HTTP状态代码操作,0各种各样的好东西,等等。
例如:
@GET
@Path("/")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getExampleUser() {
User exampleUser = new User();
return Response.ok(exampleUser).build();
}
的WADL产生看起来是一样的,但现在的响应部分显示没有返回类型和模式的证据。
<response>
<representation mediaType="application/json"/>
<representation mediaType="application/xml"/>
</response>
我的问题
是否有可能从丰富的自动生成WADL文件中获益,同时还能够让我的终点回到更加灵活Response
对象?
或者,我如何处理重定向,缓存和其他基本API功能,同时仍然从我的端点定义中返回特定的对象类型?
哟slifty - 你找到了自己的答案吗?我一直在寻找相同的东西。谢谢! –