简体   繁体   English

使用 http PUT 方法查询参数 - REST API

[英]Query parameter with http PUT method - REST API

I am passing request object and path variables in my http PUT method to update a record.我正在通过我的 http PUT 方法中的请求 object 和路径变量来更新记录。 Is it ok to pass additional data (such as timestamp) as query parameters which i want to save in the final record that has on additional field(say timestamp) as compared to request object?与请求 object 相比,是否可以将附加数据(例如时间戳)作为查询参数保存在具有附加字段(例如时间戳)的最终记录中?

Is it ok to pass additional data (such as timestamp) as query parameters which i want to save in the final record that has on additional field(say timestamp) as compared to request object?与请求 object 相比,是否可以将附加数据(例如时间戳)作为查询参数保存在具有附加字段(例如时间戳)的最终记录中?

Short answer: that probably doesn't mean what you think it does.简短的回答:这可能并不意味着你认为它做了什么。

Is it OK to use query parameters in a PUT request?可以在 PUT 请求中使用查询参数吗? Absolutely.绝对地。 Query parameters are just another piece of the resource identifier.查询参数只是资源标识符的另一部分。

/15f3221f-ee3b-4155-bc75-f80855a9187e/abc
/15f3221f-ee3b-4155-bc75-f80855a9187e?abc

Those are two different resource identifiers, and the machines won't assume that they identify the same resource, but all of the http methods that would apply to one would also apply to the other, and mean the same thing.这是两个不同的资源标识符,机器不会假设它们标识相同的资源,但是适用于其中一个的所有 http 方法也适用于另一个,并且含义相同。

There's nothing magic about abc of course, you could use a timestamp there当然, abc没有什么神奇之处,你可以在那里使用时间戳

/15f3221f-ee3b-4155-bc75-f80855a9187e?1970-01-01

Changing the timestamp changes the identifier;更改时间戳会更改标识符; as far as general purpose components are concerned, these next two examples identify different resources就通用组件而言,接下来的两个示例标识了不同的资源

/15f3221f-ee3b-4155-bc75-f80855a9187e?1970-01-01
/15f3221f-ee3b-4155-bc75-f80855a9187e?1970-01-02

You might imagine them as two different pages of a desktop calendar.您可以将它们想象为桌面日历的两个不同页面。 Modifying the list of appointments in your 1970-01-02 document shouldn't change your 1970-01-01 calendar at all.修改 1970-01-02 文档中的约会列表根本不会更改 1970-01-01 日历。

Metadata about a representation would normally be embedded within the representation itself (think HEAD element in an HTML document) or in the HTTP Headers.有关表示的元数据通常嵌入在表示本身中(想想 HTML 文档中的 HEAD 元素)或 HTTP 标头中。 As far as I can tell, we don't have a standardized header that matches the semantics you want.据我所知,我们没有与您想要的语义相匹配的标准化 header。

All that said: the server has a LOT of freedom in how it interprets a request to update the representation of /15f3221f-ee3b-4155-bc75-f80855a9187e?1970-01-02 .综上所述:服务器在解释更新/15f3221f-ee3b-4155-bc75-f80855a9187e?1970-01-02表示的请求方面有很大的自由度。 For instance, the updating of that resource might also update the representations of many other resources.例如,该资源的更新也可能会更新许多其他资源的表示。

(Do keep in mind caching, though - there are only a limited number of ways we can advise a general purpose client that some cached representations have been invalidated by a request.) (但请记住缓存 - 我们只能通过有限的方式告知通用客户端某些缓存表示已被请求无效。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM