如何在浏览器中指定Restlet响应的格式?

发布于 2024-08-30 16:18:55 字数 389 浏览 3 评论 0原文

我已经开始向 REST 介绍自己。我使用 Restlet 作为 REST 框架。 我已经定义了一个带有多种响应格式的 GET 方法的资源,就像

@Get("xml")
@Get("json")

我现在想用浏览器测试我定义的响应格式一样,但我不知道必须在 URL 中指定哪个参数才能获取格式。 就像:

http://localhost:8182/members?type=xml

我尝试了一些参数名称,但找不到正确的参数名称。我知道一定有这样一个参数,因为我已经在URL中看到过它,但我忘记了名字并且在网上找不到它。 使用restlet的时候这个参数的名字是怎样的呢?

如果有人能帮助我,我会很高兴 谢谢, 马丁

i've started to introduce myself into REST. I use as REST-framework Restlet.
I have defined a resource with methods for the GET with several response formats like

@Get("xml")
@Get("json")

I now want to test my defined response-formats with my browser, but I don't know which parameter I have to specify in my URL to get the format.
Something like:

http://localhost:8182/members?type=xml

I've tried some param-names, but I couldn't find the right param-name. I know that there must be such a parameter, because I've seen it already in an URL, but i forgot the name and couldn't find it in the net.
How is the name of this parameter when using restlet?

I would be pleased, if somebody can help me,
thanks,
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唠甜嗑 2024-09-06 16:18:55

Martin 使用 Restlet API,它定义了自己的更简单的注释(例如 ash @Get)。 Restlet 框架确实支持 JAX-RS API 和注释(例如 @GET、@Produces 等),但作为扩展的一部分。

要在浏览器中选择媒体类型,您需要使用“media=xml”查询参数而不是“type=xml”,但这可以在 Restlet 应用程序实例的 TunnelService 中进行配置。

希望这有帮助。如需进一步帮助,请使用 Restlet 邮件列表:
http://www.restlet.org/community/lists

最诚挚的问候

Martin uses the Restlet API which defines its own simpler annotations (such ash @Get). The Restlet Framework does support JAX-RS API and annotations (such as @GET, @Produces, etc.) but as part of an extension.

To select the media type in your browser you need to use the "media=xml" query parameter instead of "type=xml", but this can be configured in the TunnelService of your Restlet Application instance.

Hope this helps. For further help, please use the Restlet mailing list:
http://www.restlet.org/community/lists

Best regards

万劫不复 2024-09-06 16:18:55

尝试将请求中的“Accept”标头设置为“text/xml”或“text/json”。

我还认为,如果您想返回某种 mime 类型的资源,您可以使用 @Produces("text") 注释,而不是 @GET (除非这是新方式)。嗯..我看到根据 API 你可以使用 @GET 来做到这一点。

我相信您正在寻找的 URI 参数是 ?media=json

Try setting the "Accept" header in your request to "text/xml" or "text/json".

I also thought if you wanted to return a resource in a certain mime-type you used the @Produces("text") annotation, not the @GET (unless this is the new way). Hmm..I see according to the API you can do it with the @GET.

I believe the URI parameter you are looking for is ?media=json

初与友歌 2024-09-06 16:18:55

我正在使用示例项目org.restlet.example.serialization.gae.server
这个线程帮助了我,所以我做了一些小改动(只是在引号和括号中添加了 "json" )以获得 JSON 响应:

@Get("json")
public Contact retrieve() {
    return contact;
}

I'm on example project org.restlet.example.serialization.gae.server
and this thread helped me, so I've done small change (just added "json" in quotes and parenthesis) to get JSON response:

@Get("json")
public Contact retrieve() {
    return contact;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文