【问题标题】:Performing an HTTP PATCH using Ruby curb使用 Ruby 遏制执行 HTTP PATCH
【发布时间】:2012-09-28 02:35:39
【问题描述】:

我正在尝试使用遏制进行 HTTP PATCH。查看代码,似乎没有为此公开的方法。有什么办法可以使用遏制来做补丁?如果没有,Ruby 中还有哪些其他库或方法可以完成此任务?

【问题讨论】:

    标签: ruby rest curl curb


    【解决方案1】:

    使用最新版本 (v0.8.1) PATCH 受支持,即使它在 Curl::Easy 接口中未明确提供(请参阅 lib/curl/easy.rb)。

    可以找到快捷方式here

    # 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 动词只是简单地传递给简单的接口,如下所示:

    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)
    

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多