REST API:GET与身体的要求身体、REST、API、GET

2023-09-03 01:22:18 作者:牵过你的手看过海滩日落

我想实现一个REST API,需要一个身体在我的GET请求。 (像这里讨论: HTTP GET请求与身)

I want to implement a REST API and need a body on my GET requests. (Like discussed here: HTTP GET with request body)

是否有HTTP客户端这是不能够将主体发送用GET请求?提琴手是能够做到这一点,虽然消息框是红色的。

Are there http clients which are not able to send a body with a GET request? Fiddler is able to do it, although the message box is red.

推荐答案

作为一般规则,在休息GET的想法是,你的任何参数都发送的网址。当你包括对这个问题的回答表明,这是可行的,但错过休息,这是有一个一致的webbish接口的地步。如果你想复杂的数据传递给你的终点,你可能想使用POST,你的用户会希望有一个机构。我强烈建议重新考虑该实现。

As a general rule, the idea of a GET in REST is that any of your parameters are sent in the URL. As the answer on the question you included indicates, it's doable but misses the point of REST, which is to have a consistent webbish interface. If you want to pass complex data to your endpoint, you probably want to use a POST, which your users will expect to have a body for. I'd highly recommend reconsidering that implementation.

但你的实际问题,肯定有一些不能在一个GET发送的身体客户。主要是我想像你的客户会计划,比方说,蟒蛇的urlib2,而你的可以的设置体上得到的,它是不是真的打算使用的模块,所以你强迫程序员变得怪异。更重要的是,REST API的思路是将客户端无关,这就是为什么它的声音,我喜欢你的API的设计应该在这里返工。

But to your actual question, sure there are clients that can't send a body on a GET. Mostly I'd imagine your clients will be programmatic, say, python's urlib2, and while you can set a body on GET, it is not really the intended use of the module, so you're forcing the programmer to get weird. More importantly, the idea of the REST api is to be client-agnostic, which is why it sounds to me like your API design should be reworked here.