Ruby的HTTP 客户端 Faraday

码农软件 · 软件分类 · 网络工具包 · 2019-02-27 22:44:23

软件介绍

Faraday 是一个Ruby 的HTTP 客户端开发库,提供了一个通用的接口,支持如下适配器:

示例代码:

conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
  faraday.request  :url_encoded             # form-encode POST params
  faraday.response :logger                  # log requests to STDOUT
  faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
end

# set proxy with string
conn.options.proxy = "http://user:password@example.org/"

# set proxy with hash
conn.options.proxy = { :uri => 'http://user:passwordexample.org' }

# specify proxy user/pass
conn.options.proxy = { :uri => 'http://user:pass.org',
  :user => 'user',
  :password => 'pass' }

## GET ##

response = conn.get '/nigiri/sake.json'     # GET http://sushi.com/nigiri/sake.json
response.body

conn.get '/nigiri', { :name => 'Maguro' }   # GET /nigiri?name=Maguro

conn.get do |req|                           # GET http://sushi.com/search?page=2&limit=100
  req.url '/search', :page => 2
  req.params['limit'] = 100
end

## POST ##

conn.post '/nigiri', { :name => 'Maguro' }  # POST "name=maguro" to http://sushi.com/nigiri

# post payload as JSON instead of "www-form-urlencoded" encoding:
conn.post do |req|
  req.url '/nigiri'
  req.headers['Content-Type'] = 'application/json'
  req.body = '{ "name": "Unagi" }'
end

## Per-request options ##

conn.get do |req|
  req.url '/search'
  req.options.timeout = 5           # open/read timeout in seconds
  req.options.open_timeout = 2      # connection open timeout in seconds

  # set proxy with string
  req.options.proxy = "http://user:password@example.org/"

  # set proxy with hash
  req.options.proxy = { :uri => 'http://user:passwordexample.org' }

  # specify proxy user/pass
  req.options.proxy = { :uri => 'http://user:pass.org',
    :user => 'user',
    :password => 'pass' }
end

本文地址:https://codercto.com/soft/d/283.html

集创思维设计矩阵

集创思维设计矩阵

慈思远 / 电子工业出版社 / 2017-4 / 72.00元

《集创思维设计矩阵——写给互联网人的设计指南》总结了作者从业7年以来的设计经历,在大量企业所面对的设计问题基础上,提出了枪型思维,即如何给产品更准确的定位。 在定位准确的基础上加以设计,提出了设计中高维度融合低维度的设计思维,即设计者可以从商业逻辑推演到设计逻辑,让设计更加精确;又提出了设计和计算的博弈,指出在每一步创新的基础上,设计者一定要清晰地评判设计的代价。这样设计后的产品才是可以和企......一起来看看 《集创思维设计矩阵》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具