web-services - RESTful 触发服务器端事件的方式

标签 web-services api rest restful-architecture

我有一种情况,我需要我的 API 来调用触发服务端事件,客户端不需要任何信息(除了身份验证),并且服务器不需要返回任何信息。由于这不太适合标准的 CRUD/资源交互,我应该将此作为我做错了什么的指标,还是有 RESTful 设计模式来处理这些情况?

最佳答案

您的客户可以:

POST /trigger

服务器将响应 202 Accepted .

这样,您的请求仍然可以包含适当的身份验证 header ,并且如果您需要客户端提供实体,或者需要返回包含有关如何查询事件状态的信息的响应,API 可以在 future 扩展。

您在这里尝试做的事情没有任何“非 RESTful”; REST 原则不必与资源上的 CRUD 操作相关联。

spec for 202说:

The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.



鉴于定义中的“应该”,您没有义务在响应中发送任何内容。

关于web-services - RESTful 触发服务器端事件的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8492207/

相关文章:

java - 您应该将扩展 Application 的类放置在 jax.rs 中的何处

php - 如何在 PHP 中创建 Web API 服务

java - 带有 Java 的 Wss4jSecurityInterceptor 的 SOAP WS-Addressing 属性

php - $facebook->api ('/me' );有时不加载

json - 我们如何通过网络安全地将 API key 和 secret token 交付给用户?

java - Jersey : the resource is not available

ajax - 如何在发送 AJAX 请求时隐藏 API key ?

rest - REST url 的 WSO2 ESB 主题订阅

javascript - 使用功能文件更新 JSON 元素

java - 休息资源 : get id of subentity without extra request