使用Ruby curb执行HTTP PATCH [英] Performing an HTTP PATCH using Ruby curb

查看:161
本文介绍了使用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)

这篇关于使用Ruby curb执行HTTP PATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆