REST Client – simple DSL for accessing HTTP and REST resources

https://github.com/rest-client/rest-clienthttps://github.com/jnunemaker/httparty
http://ruby-doc.org/stdlib-2.1.2/libdoc/net/http/rdoc/Net/HTTP.html
https://www.imququ.com/post/four-ways-to-post-data-in-http.html
工作中常用到获取一个xml或者json格式的数据进行解析,获取我们希望拿到的有效数据,这时候用的是http的get请求,当我们提交表单和上传文件的时候,用的是http的post请求,post请求的contentType分两种,提交普通的表单的时候,Content-Type是"application/x-www-form-urlencoded",上传文件的时候,Content-Type是"multipart/form-data"这个可以通过浏览器的调试工具查看点击F12打开页面调试工具,然后选择"Network"->"Headers"->"Request Headers"->"Content-Type"

接下来我们分别看一下应用的场景

(一)REST Client获取xml/json数据

(1)xmlresponse = RestClient.get(url)
url_hash = Hash.from_xml(response.body)

(2)json

response = RestClient.get(url_list[index])
url_hash = JSON.parse(response.body)[‘headline_videos‘]

(二)httpparty获取json数据
response = HTTParty.get(‘https://api.stackexchange.com/2.2/questions?site=stackoverflow‘)

==============================

RestClient最大的优势在于在post请求的时候能够上传一个文件,
 module ClassMethods
    def upload_image(file_path)
      timestamp = Time.now.to_i

      response = RestClient.post Settings.upload.image.url, {
        uid: Settings.upload.image.uid,
        appkey: Settings.upload.image.appkey,
        timestamp: timestamp,
        sign: sign(timestamp),
        filename: "ott_cms_#{timestamp}",
        duplmd5: Settings.upload.image.duplmd5,
        file: File.new(file_path)
      }

      case response.code
      when 200
        parse_upload_response response
      else
        { errors: ["图片上传服务暂时不可用"] }
      end
    end

REST Client – simple DSL for accessing HTTP and REST resources

时间: 2024-11-15 00:40:46

REST Client – simple DSL for accessing HTTP and REST resources的相关文章

Advanced Rest Client调试RESTFul

Advanced REST client 基于浏览器的Rest Client工具 在chrome或者firefox浏览器都有很多插件,我一般都是使用chrome浏览器,在chrome的webstore中可以搜索到自己想要的插件.这里就讲讲Advance REST Client,Postman-REST Client,DEV HTTP CLIENT,Simple REST Client 网页开发者辅助程序来创建和测试自定义HTTP请求.它是一款非常强大,使用简单的客户端测试工具,得到了程序员的好评

LMAX Disruptor – High Performance, Low Latency and Simple Too 转载

原文地址:http://www.symphonious.net/2011/07/11/lmax-disruptor-high-performance-low-latency-and-simple-too/ The LMAX disruptor is an ultra-high performance, low-latency message exchange between threads. It's a bit like a queue on steroids (but quite a lot

Accessing Lua global variables from c++

http://blog.csdn.net/cnjet/article/details/5909541 Calling Lua scripts from c++’s example was written in post How to embed Lua 5.1 in C++. Now, let us look at how to access Lua’s global variables from c++. Value passing between c++ and Lua rely on Lu

REST client 基于浏览器的测试工具

以前在开发webservice服务,都是自己基于HTTP协议,自己写一个测试程序来进行测试,最近在研究RestFul,对以前webservice服务进行了重构,总结了不少经验,今天就给大家介绍下几款Rest Client的测试工具. REST介绍 所谓REST,是Representational State Transfer,这个词汇的中文翻译很不统一,而且很晦涩,有叫“具象状态传输”,有叫“表象化状态转变”,等等. REST风格的Web服务,是通过一个简洁清晰的URI来提供资源链接,客户端通过

(转)wcf client与webservice通信(-)只修改配置文件而改变服务端

http://www.cnblogs.com/yiyisawa/archive/2008/12/16/1356191.html 问题: 假设有一个大型系统新版本使用wcf 作为服务端,生成wcf client 调用可以调用正常. 那如果当wcf 服务端出现问题或其他的原因我想再用回以前老版本的webservice或是jms server ,但客户端调用还是通过wcf client 调用.只通过更改配置来实现. 一.web service项目,添加一个普通service class .代码如下:

网上搜集第三方(二)

這是我收集了一些第三方的 Library,大部份都還沒用過Orz,只是這樣整理以後要用到的時候會比較好找到. UI UI Design alertView Menu(選單) Side ViewController UICollectionView Segment Control Others 動畫 影像特效 模糊.毛玻璃效果(Blur) 畫面轉換 各種統計圖表 Line Bar Pie Others Pull To ReFresh Notification Auto Layout Data St

OAuth 2 Developers Guide

Introduction This is the user guide for the support for OAuth 2.0. For OAuth 1.0, everything is different, so see its user guide. This user guide is divided into two parts, the first for the OAuth 2.0 provider, the second for the OAuth 2.0 client. Fo

Securing Spring Cloud Microservices With OAuth2

From Zero to OAuth2 in Spring cloud Today I am presenting hours of research about a (apparently) simple question: “How can I maintain security in my microservices architecture?”. The task is to enable a simple but mighty possibility to secure spring

OPC and .NET

Note: recent OPC standards, including Unified Architecture (UA) and Express Interface (Xi) were designed to natively support .NET. The content of this page largely relates to techniques for using the older COM-based OPC specifications from .NET appli