使用Ruby curb执行HTTP PATCH

我正在尝试使用curb进行HTTP PATCH。 查看代码,似乎没有为此公开方法。 有没有办法用路边做PATCH? 如果没有,Ruby中还有哪些其他库或方法可以实现这一目标?

使用curb最新版本(v0.8.1),即使在Curl::Easy界面中没有明确提供PATCH也支持PATCH (参见lib/curl/easy.rb )。

你可以在这里找到一个快捷方法:

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

有了它,您可以执行如下PATCH请求:

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

在引擎盖下, PATCH动词简单地传递给easy界面,如下所示:

 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)