关于 RESTful Web 服务的 2 个问题 [英] 2 questions about RESTful Web Services

查看:48
本文介绍了关于 RESTful Web 服务的 2 个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 RESTful Web 服务的新手.我有以下两个问题:

I am new to RESTful web services. I have the following 2 questions:

  1. GET、POST、DELETE、PUT、TRACE、HEAD、OPTIONS 是 Http 中唯一可以用于 RESTful Web 服务的动词吗?

  1. Are GET, POST, DELETE, PUT, TRACE, HEAD, OPTIONS, the only verbs in Http that I can use for RESTful web services?

如何创建和使用自定义动词?

How do I create and use a custom verb?

我正在使用 Java 和 Jersey 来创建我的 RESTful Web 服务.

I'm using Java and Jersey for creating my RESTful web services.

推荐答案

问题 1 的答案是肯定的,因为它们受到 HTTP 规范的限制.然而,实际上,大多数 REST 应用程序仅使用 GET 和 POST,因为所有 Internet 基础设施都最广泛地支持这些.然后问题二的答案是否定的,您不能创建自定义动词.

The answer to question 1 is, yes as they are restricted by the HTTP specification. However as a matter of practice, most REST applications use only GET and POST, as these are most widely supported by all of the Internet infrastructure. And then the answer to question two is no, you can't create a custom verb.

在使用 HTTP 动词时必须考虑的事情是 GET 应该没有副作用,因为客户端可以随时重新发送 GET(如果检测到通信失败).然而,客户端最多只能发送一次 POST,因此这应该用于任何导致无法重复的更改(如插入).

The thing you have to consider in your use of the HTTP verbs is that a GET should have no side effects, as the client is free to resend a GET at any time (in the event a communication failure was detected). A POST however can be sent by the client at most once, so this should be used for anything that causes a change that cannot be repeated (like an insert).

通常,您会将应用程序中所需的动词"定义为 URL 的一部分,而不是 HTTP 动词.

Normally you would define what "verb" you want in your application as part of the URL, not as the HTTP verb.

这篇关于关于 RESTful Web 服务的 2 个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆