Performing an HTTP PATCH using Ruby curb
题
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?
解决方案
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)
不隶属于 StackOverflow