From b67c5d53e0b5be07afed07d0a2f60e99d72f7fb9 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Tue, 6 Oct 2020 16:44:35 +0100 Subject: [PATCH] starting notes on the next minor version --- doc/release_notes/0_9_0.md | 38 ++++++++++++++++++++++++++++++++++++++ examples/post.rb | 6 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 doc/release_notes/0_9_0.md diff --git a/doc/release_notes/0_9_0.md b/doc/release_notes/0_9_0.md new file mode 100644 index 00000000..7a50b669 --- /dev/null +++ b/doc/release_notes/0_9_0.md @@ -0,0 +1,38 @@ +# 0.9.0 + +## Features + +### Multiple requests with specific options + +You can now pass a third element to the "request element" of an array to `.request`. + +```ruby +requests = [ + [:post, "https://url/post", { form: { foo: "bar" } }], + [:post, "https://url/post", { form: { foo: "bar2" } }] +] +HTTPX.request(requests) +# or, if you want to pass options common to all requests +HTTPX.request(requests, max_concurrent_requests: 1) +``` + + +### HTTPX::Session#build_request + +`HTTPX::Session::build_request` is now public API from a session. You can now build requests before you send them. These request objects are still considered somewhat "internal", so consider them immutable and **do not rely on its API**. Just pass them forward. + +Note: this API is only available for instantiated session, so there is no `HTTPX.build_request`. + + +```ruby + +HTTPX.wrap do |http| + requests = [ + http.build_request(:post, "https://url/post", { form: { foo: "bar" } }), + http.build_request(:post, "https://url/post", { form: { foo: "bar2" } }) + ] + http.request(requests) + # or, if you want to pass options common to all requests + http.request(requests, max_concurrent_requests: 1) +end +``` \ No newline at end of file diff --git a/examples/post.rb b/examples/post.rb index 5188c890..62c31af1 100644 --- a/examples/post.rb +++ b/examples/post.rb @@ -6,9 +6,9 @@ include HTTPX URLS = %w[http://nghttp2.org/httpbin/post] * 102 $HTTPX_DEBUG = true -client = Client.new -requests = URLS.map { |url| client.request(:post, url, json: {"bang" => "bang"}) } -responses = client.send(*requests) +client = Session.new +requests = URLS.map { |url| client.build_request(:post, url, json: {"bang" => "bang"}) } +responses = client.request(*requests) responses.each do |res| puts "status: #{res.status}"