Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (39 sloc) 1.482 kb
5405e7d @sferik Cleanup and fix
sferik authored
1 Faraday Middleware
2 ==================
7d083d0 @pengwynn mashify, multi_json
authored
3
5d60ca1 @mislav update Readme
mislav authored
4 A collection of useful [Faraday][] middleware. [See the documentation][docs].
7d083d0 @pengwynn mashify, multi_json
authored
5
5405e7d @sferik Cleanup and fix
sferik authored
6 gem install faraday_middleware
7d083d0 @pengwynn mashify, multi_json
authored
7
f4998c1 @mislav list dependencies in Readme
mislav authored
8 Dependencies
9 ------------
10
11 Some dependent libraries are needed only when using specific middleware:
12
13 * FaradayMiddleware::EncodeJson & FaradayMiddleware::ParseJson: "json"
14 for ruby older than 1.9
15 * FaradayMiddleware::ParseXml: "multi_xml"
16 * FaradayMiddleware::OAuth: "simple_oauth"
17 * FaradayMiddleware::Mashify: "hashie"
18 * FaradayMiddleware::Rashify: "rash"
19 * FaradayMiddleware::Instrumentation: "activesupport"
20
5d60ca1 @mislav update Readme
mislav authored
21 Examples
5405e7d @sferik Cleanup and fix
sferik authored
22 --------
7d083d0 @pengwynn mashify, multi_json
authored
23
5d60ca1 @mislav update Readme
mislav authored
24 ``` rb
25 require 'faraday_middleware'
7d083d0 @pengwynn mashify, multi_json
authored
26
5d60ca1 @mislav update Readme
mislav authored
27 ## in Faraday 0.8 or above:
28 connection = Faraday.new 'http://example.com/api' do |conn|
29 conn.request :oauth2, 'TOKEN'
30 conn.request :json
7d083d0 @pengwynn mashify, multi_json
authored
31
5d60ca1 @mislav update Readme
mislav authored
32 conn.response :xml, :content_type => /\bxml$/
33 conn.response :json, :content_type => /\bjson$/
8293779 @reddavis gem install faraday_middleware not faraday-middleware
reddavis authored
34
5d60ca1 @mislav update Readme
mislav authored
35 conn.use :instrumentation
36 conn.adapter Faraday.default_adapter
37 end
7d083d0 @pengwynn mashify, multi_json
authored
38
5d60ca1 @mislav update Readme
mislav authored
39 ## with Faraday 0.7:
40 connection = Faraday.new 'http://example.com/api' do |builder|
41 builder.use FaradayMiddleware::OAuth2, 'TOKEN'
42 builder.use FaradayMiddleware::EncodeJson
7d083d0 @pengwynn mashify, multi_json
authored
43
5d60ca1 @mislav update Readme
mislav authored
44 builder.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/
45 builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
7d083d0 @pengwynn mashify, multi_json
authored
46
5d60ca1 @mislav update Readme
mislav authored
47 builder.use FaradayMiddleware::Instrumentation
48 builder.adapter Faraday.default_adapter
49 end
50 ```
51
52
53 [faraday]: https://github.com/technoweenie/faraday#readme
54 [docs]: https://github.com/pengwynn/faraday_middleware/wiki
Something went wrong with that request. Please try again.