本文介绍了当我通过 GET 调用向服务器写入内容时,它是否违反了 RESTful?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录用户在我网站上的操作,不仅是 POST 请求,还有 GET 请求.例如,假设用户尝试使用以下 GET 请求搜索城市:

I would like to record user actions on my website, not only on POST requests, but on GET requests as well. For example, suppose the user tries to search for a city with the following GET request:

/search_city?name=greenville

/search_city?name=greenville

此请求将返回名称为greenville"的城市列表.我还想将此关键字保存到服务器,作为用户的搜索历史".我打算在处理 GET 调用期间只保存这些信息.

This request would return a list of cities with the name "greenville". I'd also like to save this keyword to the server, as the "search history" for a user. I'm planning to just do the save this information during the processing of the GET call.

这是否违反了 RESTful 原则?如果是,我该如何正确执行此操作?

Is this a violation to RESTful principles? If yes, how do I do this the right way?

推荐答案

我认为这种审计日志是一种不可见的副作用.如果下一个人打电话

I see this kind of audit logging as an invisible side-effect. If the next person to call

/search_city?name=greenville

仍然得到相同的答案,那么您的 GET 是有效的.类似的情况是某种缓存构建,GET 的调用者并不(不需要)知道您正在做一些额外的工作.

still gets the same answer then your GET is valid. A similar case would be some kind of cache building, the caller of GET doesn't (need to) know that you're doing some extra work.

专注于正式的 API - 发送这个请求得到这个响应.

Focus on the formal API - send this request get this response.

这篇关于当我通过 GET 调用向服务器写入内容时,它是否违反了 RESTful?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:47
查看更多