使用Ruby curb执行HTTP PATCH

问题描述:

我尝试使用curb进行HTTP PATCH。看看代码,似乎没有为此暴露的方法。有什么办法使用curb做一个PATCH吗?

I'm trying to do an HTTP PATCH using curb. Looking through the code, there doesn't seem to be a method exposed for this. Is there any way to use curb to do a PATCH? If not, what other libraries or methods are there in Ruby to accomplish this?

使用curb最新版本(v0.8.1) PATCH 是支持的,即使它在 Curl :: Easy 接口中没有显式可用(参见 lib / curl / easy.rb )。

With curb latest version (v0.8.1) PATCH is supported even though it is not explicitly available within the Curl::Easy interface (see lib/curl/easy.rb).

您可以找到一个快捷方法此处

You can find a shortcut method here:

# see lib/curl.rb
module Curl
  # ...
  def self.patch(url, params={}, &block)
    http :PATCH, url, postalize(params), nil, &block
  end
  # ...
end

使用它,您可以执行 PATCH 请求,如下所示:

With it you can perform a PATCH request as follow:

curl = Curl.patch("http://www.example.com/baz", {:foo => "bar"})

在此引擎下, PATCH 动词只是传递到easy界面如下: / p>

Under the hood, the PATCH verb is simply passed to the easy interface as follow:

curl = Curl::Easy.new(url)

# `http` is a method implemented within the C extensions of curb
# see `ruby_curl_easy_perform_verb_str`. It allows to set the HTTP
# verb by calling `curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, verb)`
# and perform the request right after
curl.http(:PATCH)