这个客户端请求应该使用哪种HTTP方法?

huangapple go评论106阅读模式
英文:

Which HTTP method to use for this client request?

问题

我正在使用Java开发一个REST Web服务,该服务在客户端请求时处理请求体并将输出返回给客户端。客户端发送的请求体包含一个GO(编程语言)程序,服务器在服务器上执行(运行)该程序,并将程序的标准输出返回给客户端。现在,由于请求体包含一些文本(程序),我不能使用HTTP GET方法来实现。我可以使用PUT或POST,但我了解到它们(PUT和POST)通常用于更新/创建资源。由于我在这里不创建任何资源,使用PUT或POST在概念上是否正确?如果不正确,我应该使用哪种HTTP方法?

英文:

I am developing a REST web service in Java which on clients' request processes the request body and gives the output to the client. The request body sent by the client consists of a GO(programing language) program which the server executes(runs) on the server machine and returns the standard output of the program back to the client. Now since the request body contains some text(program), I cannot use HTTP GET method to do that. I can use PUT or POST, but I have learnt that they(PUT and POST) are generally used for updating/creating a resource. Since, I am not creating any resource here, is it conceptually correct to use PUT or POST. If not, which is the HTTP method that I need to use?

答案1

得分: 2

根据你解决的问题并与现有的生产解决方案进行比较,我建议你在你的场景中使用POST方法。

  • 推理 - 解决类似问题的示例生产代码:

假设你要解决的问题是这样的:
客户使用Go编程语言提交代码,你的服务器编译并运行它,然后给出输出。假设这与许多在线编码网站(如hackerEarth)类似,他们的API文档页面和提供的示例Python代码显示,我们可以使用HTTP:POST方法将代码提交到服务器进行处理。

POST方法的设计目的是允许统一的方法来覆盖以下功能:
提供一块数据,例如提交表单的结果,给数据处理过程;

PUT方法请求将封装的实体存储在提供的请求URI下。如果请求URI引用的是已经存在的资源,则应将封装的实体视为修改后的版本,该版本驻留在源服务器上。

  • 根据上述陈述,我们可以得出结论,在你解决的问题的上下文中,你正在请求服务器对封装的实体进行一些数据处理,因此可以使用POST方法。

英文:

Looking at the problem you are solving and comparing to an existing production solution , I suggest that you can use POST in your scenario.

  • Reasoning - Example Production code solving similar problem:-

Assuming that the problem you are trying to solve is this:-
Clients submit code in Go programming language, Your server compiles it, runs it and then gives the output. Assuming also that, it is somewhat similar to many online coding websites like hackerEarth, their API documentation page and the sample python code provided show that we can use HTTP:POST to submit code to the server for its processing.

POST is designed to allow a uniform method to cover the following functions:
Providing a block of data, such as the result of submitting a
form, to a data-handling process;

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server.

  • Referring to the above statements, we can conclude that in the context of this problem which you are solving, you are requesting the server to do some data-handling for the enclosed entity, so you can use POST.

huangapple
  • 本文由 发表于 2016年3月23日 14:08:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/36170941.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定