Performing an HTTP PATCH using Ruby curb

江枫思渺然 提交于 2019-12-13 02:46:55

问题


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?


回答1:


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

With it you can perform a PATCH request as follow:

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

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)


来源:https://stackoverflow.com/questions/12632859/performing-an-http-patch-using-ruby-curb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!