mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
69 lines
2.1 KiB
Plaintext
69 lines
2.1 KiB
Plaintext
= faraday
|
|
|
|
Experiments in a REST API lib
|
|
|
|
Super alpha! Don't use it if you mind throwing away all the code when I change
|
|
the API on a whim.
|
|
|
|
== Usage
|
|
|
|
# uses Net/HTTP, no response parsing
|
|
conn = Faraday::Connection.new("http://sushi.com")
|
|
conn.extend Faraday::Adapter::NetHttp
|
|
resp = conn.get("/sake.json")
|
|
resp.body # => %({"name":"Sake"})
|
|
|
|
# uses Net/HTTP, Yajl parsing
|
|
conn = Faraday::Connection.new("http://sushi.com")
|
|
conn.extend Faraday::Adapter::NetHttp
|
|
conn.response_class = Faraday::Response::YajlResponse
|
|
resp = conn.get("/sake.json")
|
|
resp.body # => {"name": "Sake"}
|
|
|
|
# uses Typhoeus, no response parsing
|
|
conn = Faraday::Connection.new("http://sushi.com")
|
|
conn.extend Faraday::Adapter::Typhoeus
|
|
resp = conn.get("/sake.json")
|
|
resp.body # => %({"name":"Sake"})
|
|
|
|
# uses Typhoeus, Yajl parsing, performs requests in parallel
|
|
conn = Faraday::Connection.new("http://sushi.com")
|
|
conn.extend Faraday::Adapter::Typhoeus
|
|
conn.response_class = Faraday::Response::YajlResponse
|
|
resp1, resp2 = nil, nil
|
|
conn.in_parallel do
|
|
resp1 = conn.get("/sake.json")
|
|
resp2 = conn.get("/unagi.json")
|
|
|
|
# requests have not been made yet
|
|
resp1.body # => nil
|
|
resp2.body # => nil
|
|
end
|
|
resp1.body # => {"name": "Sake"}
|
|
resp2.body # => {"name": "Unagi"}
|
|
|
|
== Testing
|
|
|
|
* Typhoeus and Yajl are needed for tests :(
|
|
* Live Sinatra server is required for tests: `ruby test/live_server.rb` to start it.
|
|
|
|
== TODO
|
|
|
|
* gracefully skip tests for Typhoeus, Yajl, and other optional libraries if they don't exist.
|
|
* gracefully skip live http server tests if the sinatra server is not running.
|
|
* lots of other crap
|
|
|
|
== Note on Patches/Pull Requests
|
|
|
|
* Fork the project.
|
|
* Make your feature addition or bug fix.
|
|
* Add tests for it. This is important so I don't break it in a
|
|
future version unintentionally.
|
|
* Commit, do not mess with rakefile, version, or history.
|
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
* Send me a pull request. Bonus points for topic branches.
|
|
|
|
== Copyright
|
|
|
|
Copyright (c) 2009 rick. See LICENSE for details.
|