<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="318182" data-post-id="318182">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="stevensonmt" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/120/20503_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  stevensonmt
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh yeah. My bad! Still feels like something not quite right about it though. Seems that a lib focused on explicitly handling web urls should maybe default to http or https rather than raising an error for a missing scheme. <code>ddsdsdf.com</code> should be recognized as an attempt at  web url, shouldn’t it? We’re all used to just skipping the <code>http://</code> part of any address we type into a browser.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="318182" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-318182" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="318182"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #31"></div>
  </section>
</div>
    <div class="postbit" id="318334" data-post-id="318334">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wojtekmach" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wojtekmach/120/999_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wojtekmach
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Hex Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="stevensonmt" data-post="32" data-topic="48494">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/48/20503_2.png" class="avatar"> stevensonmt:</div>
<blockquote>
<p>We’re all used to just skipping the <code>http://</code> part of any address we type into a browser.</p>
</blockquote>
</aside>
<p>I haven’t seen any other HTTP client (besides good old curl) doing that. Please let me know if you have any such examples.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="318334" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-318334" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="318334"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #32"></div>
  </section>
</div>
    <div class="postbit" id="318335" data-post-id="318335">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wojtekmach" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wojtekmach/120/999_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wojtekmach
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Hex Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey everyone, some Req updates since v0.4.0 below.</p>
<h2><a name="p-318335-new-step-checksum-1" class="anchor" href="#p-318335-new-step-checksum-1" aria-label="Heading link" rel="nofollow"></a>New step: <a href="https://hexdocs.pm/req/Req.Steps.html#checksum/1" rel="noopener nofollow ugc"><code>checksum</code></a></h2>
<p>Sets expected response body checksum.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; resp = Req.get!("https://httpbin.org/json", checksum: "sha1:9274ffd9cf273d4a008750f44540c4c5d4c8227c")
iex&gt; resp.status
200

iex&gt; Req.get!("https://httpbin.org/json", checksum: "sha1:bad")
** (Req.ChecksumMismatchError) checksum mismatch
expected: sha1:bad
actual:   sha1:9274ffd9cf273d4a008750f44540c4c5d4c8227c
</code></pre>
<h2><a name="p-318335-new-step-put_aws_sigv4-2" class="anchor" href="#p-318335-new-step-put_aws_sigv4-2" aria-label="Heading link" rel="nofollow"></a>New step <a href="https://hexdocs.pm/req/Req.Steps.html#put_aws_sigv4/1" rel="noopener nofollow ugc"><code>put_aws_sigv4</code></a></h2>
<p>Signs request with AWS Signature Version 4.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; req =
...&gt;   Req.new(
...&gt;     base_url: "https://s3.amazonaws.com",
...&gt;     aws_sigv4: [
...&gt;       access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
...&gt;       secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY"),
...&gt;       service: :s3
...&gt;     ]
...&gt;   )
iex&gt;
iex&gt; %{status: 200} = Req.put!(req, "/bucket1/key1", body: "Hello, World!")
iex&gt; resp = Req.get!(req, "/bucket1/key1").body
"Hello, World!"
</code></pre>
<p>Request body streaming also works (though <code>content-length</code> header must be explicitly set):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; path = "a.txt"
iex&gt; File.write!(path, String.duplicate("a", 100_000))
iex&gt; size = File.stat!(path).size
iex&gt; chunk_size = 10 * 1024
iex&gt; stream = File.stream!(path, chunk_size)
iex&gt; %{status: 200} = Req.put!(req, url: "/key1", headers: [content_length: size], body: stream)
iex&gt; byte_size(Req.get!(req, "/bucket1/key1").body)
100_000
</code></pre>
<h2><a name="p-318335-reqtesthttpshexdocspmreqreqtesthtml-3" class="anchor" href="#p-318335-reqtesthttpshexdocspmreqreqtesthtml-3" aria-label="Heading link" rel="nofollow"></a><a href="https://hexdocs.pm/req/Req.Test.html" rel="noopener nofollow ugc"><code>Req.Test</code></a></h2>
<p>Functions for creating test stubs.</p>
<blockquote>
<p>Stubs provide canned answers to calls made during the test, usually not responding at all to<br>
anything outside what’s programmed in for the test.</p>
<p><a href="https://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs" rel="noopener nofollow ugc">“Mocks Aren’t Stubs” by Martin Fowler</a></p>
</blockquote>
<p>Req has built-in support for stubs via <code>:plug</code>, <code>:adapter</code>, and (indirectly) <code>:base_url</code><br>
options. This module enhances these capabilities by providing:</p>
<ul>
<li>
<p>Stub any value with <a rel="nofollow"><code>Req.Test.stub(name, value)</code></a> and access it with<br>
<a rel="nofollow"><code>Req.Test.stub(name)</code></a>. These functions can be used in concurrent tests.</p>
</li>
<li>
<p>Access plug stubs with <code>plug: {Req.Test, name}</code>.</p>
</li>
<li>
<p>Easily create JSON responses for Plug stubs with <a rel="nofollow"><code>Req.Test.json(conn, body)</code></a>.</p>
</li>
</ul>
<h2><a name="p-318335-example-4" class="anchor" href="#p-318335-example-4" aria-label="Heading link" rel="nofollow"></a>Example</h2>
<p>Imagine we’re building an app that displays weather for a given location using an HTTP weather<br>
service:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.Weather do
  def get_rating(location) do
    case get_temperature(location) do
      {:ok, %{status: 200, body: %{"celsius" =&gt; celsius}}} -&gt;
        cond do
          celsius &lt; 18.0 -&gt; {:ok, :too_cold}
          celsius &lt; 30.0 -&gt; {:ok, :nice}
          true -&gt; {:ok, :too_hot}
        end

      _ -&gt;
        :error
    end
  end

  def get_temperature(location) do
    [
      base_url: "https://weather-service"
    ]
    |&gt; Keyword.merge(Application.get_env(:myapp, :weather_req_options, []))
    |&gt; Req.request(options)
  end
end
</code></pre>
<p>We configure it for production:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># config/runtime.exs
config :myapp, weather_req_options: [
  auth: {:bearer, System.fetch_env!("MYAPP_WEATHER_API_KEY")}
]
</code></pre>
<p>And tests:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># config/test.exs
config :myapp, weather_req_options: [
  plug: {Req.Test, MyApp.Weather}
]
</code></pre>
<p>And now we can easily stub out values <strong>in concurrent tests</strong>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">use ExUnit.Case, async: true

test "nice weather" do
  Req.Test.stub(MyApp.Weather, fn conn -&gt;
    Req.Test.json(conn, %{"celsius" =&gt; 25.0})
  end)

  assert MyApp.Weather.get_rating("Krakow, Poland") == {:ok, :nice}
end
</code></pre>
<p>Full changelog below:</p>
<h2><a name="p-318335-v0410-2024-02-19-5" class="anchor" href="#p-318335-v0410-2024-02-19-5" aria-label="Heading link" rel="nofollow"></a>v0.4.10 (2024-02-19)</h2>
<ul>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#run_finch/1" rel="noopener nofollow ugc"><code>run_finch</code></a>: Default to <code>connect_options: [protocols: [:http1, :http2]]</code>.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#run_finch/1" rel="noopener nofollow ugc"><code>run_finch</code></a>: Change version requirement to <code>~&gt; 0.17</code>, that is all versions up to <code>1.0</code>.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#put_aws_sigv4/1" rel="noopener nofollow ugc"><code>put_aws_sigv4</code></a>: Support streaming request body.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#auth/1" rel="noopener nofollow ugc"><code>auth</code></a>: Always update <code>authorization</code> header.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#decode_body/1" rel="noopener nofollow ugc"><code>decode_body</code></a>: Gracefully handle multiple content-type values.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Request.html#new/1" rel="noopener nofollow ugc"><code>Req.Request.new/1</code></a>: Use <code>URI.parse</code> for now.</p>
</li>
</ul>
<h2><a name="p-318335-v049-2024-02-14-6" class="anchor" href="#p-318335-v049-2024-02-14-6" aria-label="Heading link" rel="nofollow"></a>v0.4.9 (2024-02-14)</h2>
<ul>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#retry/1" rel="noopener nofollow ugc"><code>retry</code></a>: Raise on invalid return from <code>:retry_delay</code> function</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#run_finch/1" rel="noopener nofollow ugc"><code>run_finch</code></a>: Update to Finch 0.17</p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#run_finch/1" rel="noopener nofollow ugc"><code>run_finch</code></a>: Deprecate <code>connect_options: [protocol: ...]</code> in favour of<br>
<code>connect_options: [protocols: ...]]</code> which defaults to <code>[:http1, :http2]</code>, that is,<br>
make request using HTTP/1 but if negotiated switch to HTTP/2 over the HTTP/1 connection.</p>
</li>
<li>
<p>New step: <a href="https://hexdocs.pm/req/Req.Steps.html#put_aws_sigv4/1" rel="noopener nofollow ugc"><code>put_aws_sigv4</code></a> - signs request with AWS Signature Version 4.</p>
</li>
</ul>
<h2><a name="p-318335-v048-2023-12-11-7" class="anchor" href="#p-318335-v048-2023-12-11-7" aria-label="Heading link" rel="nofollow"></a>v0.4.8 (2023-12-11)</h2>
<ul>
<li><a href="https://hexdocs.pm/req/Req.Steps.html#put_plug/1" rel="noopener nofollow ugc"><code>put_plug</code></a>: Fix response streaming. Previously we were relying on unreleased<br>
Plug features (which may never get released). Now, Plug adapter will emit the<br>
entire response body as one chunk. Thus,<br>
<code>plug: plug, into: fn ... -&gt; {:halt, acc} end</code> is not yet supported as it<br>
requires Plug changes that are still being discussed. On the flip side,<br>
we should have much more stable Plug integration regardless of this small<br>
limitation.</li>
</ul>
<h2><a name="p-318335-v047-2023-12-11-8" class="anchor" href="#p-318335-v047-2023-12-11-8" aria-label="Heading link" rel="nofollow"></a>v0.4.7 (2023-12-11)</h2>
<ul>
<li><a href="https://hexdocs.pm/req/Req.Steps.html#put_plug/1" rel="noopener nofollow ugc"><code>put_plug</code></a>: Don’t crash if plug is not installed and :plug is not used</li>
</ul>
<h2><a name="p-318335-v046-2023-12-11-9" class="anchor" href="#p-318335-v046-2023-12-11-9" aria-label="Heading link" rel="nofollow"></a>v0.4.6 (2023-12-11)</h2>
<ul>
<li>New step: <a href="https://hexdocs.pm/req/Req.Steps.html#checksum/1" rel="noopener nofollow ugc"><code>checksum</code></a></li>
<li><a href="https://hexdocs.pm/req/Req.Steps.html#put_plug/1" rel="noopener nofollow ugc"><code>put_plug</code></a>: Fix response streaming when plug uses <code>send_resp</code> or <code>send_file</code></li>
<li><a href="https://hexdocs.pm/req/Req.Steps.html#retry/1" rel="noopener nofollow ugc"><code>retry</code></a>: Retry on <code>:closed</code></li>
</ul>
<h2><a name="p-318335-v045-2023-10-27-10" class="anchor" href="#p-318335-v045-2023-10-27-10" aria-label="Heading link" rel="nofollow"></a>v0.4.5 (2023-10-27)</h2>
<ul>
<li>
<p><code>decompress_body</code>: Remove <code>content-length</code> header</p>
</li>
<li>
<p><code>auth</code>: Deprecate <code>auth: {user, pass}</code> in favour of <code>auth: {:basic, "user:pass"}</code></p>
</li>
<li>
<p><code>Req.Request</code>: Allow steps to be <code>{mod, fun, args}</code></p>
</li>
</ul>
<h2><a name="p-318335-v044-2023-10-05-11" class="anchor" href="#p-318335-v044-2023-10-05-11" aria-label="Heading link" rel="nofollow"></a>v0.4.4 (2023-10-05)</h2>
<ul>
<li>
<p><code>compressed</code>: Check for optional depenedencies brotli and ezstd only at compile-time.<br>
(backported from v0.3.12.)</p>
</li>
<li>
<p><code>decode_body</code>: Check for optional depenedency nimble_csv at compile-time.<br>
(backported from v0.3.12.)</p>
</li>
<li>
<p><code>run_finch</code>: Add <code>:finch_private</code> option</p>
</li>
</ul>
<h2><a name="p-318335-v043-2023-09-13-12" class="anchor" href="#p-318335-v043-2023-09-13-12" aria-label="Heading link" rel="nofollow"></a>v0.4.3 (2023-09-13)</h2>
<ul>
<li>
<p><a href="https://hexdocs.pm/req/Req.html#new/1" rel="noopener nofollow ugc"><code>Req.new/1</code></a>: Fix setting <code>:redact_auth</code></p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Request.html" rel="noopener nofollow ugc"><code>Req.Request</code></a>: Add <code>Req.Request.get_option_lazy/3</code></p>
</li>
<li>
<p><a href="https://hexdocs.pm/req/Req.Request.html" rel="noopener nofollow ugc"><code>Req.Request</code></a>: Add <code>Req.Request.drop_options/2</code></p>
</li>
</ul>
<h2><a name="p-318335-v042-2023-09-04-13" class="anchor" href="#p-318335-v042-2023-09-04-13" aria-label="Heading link" rel="nofollow"></a>v0.4.2 (2023-09-04)</h2>
<ul>
<li>
<p><a href="https://hexdocs.pm/req/Req.Steps.html#put_plug/1" rel="noopener nofollow ugc"><code>put_plug</code></a>: Handle response streaming on Plug 1.15+.</p>
</li>
<li>
<p>Don’t warn on mixed-case header names</p>
</li>
</ul>
<h2><a name="p-318335-v041-2023-09-01-14" class="anchor" href="#p-318335-v041-2023-09-01-14" aria-label="Heading link" rel="nofollow"></a>v0.4.1 (2023-09-01)</h2>
<ul>
<li>Fix Req.Request Inspect regression</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="318335" data-batch-url="/posts/batch_likers">
                        26
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-318335" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="318335"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="318374" data-post-id="318374">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sergio" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sergio/120/26966_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sergio
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This release looks tremendous, appreciate all your hard work! <img src="https://forum.elixirforum.com/images/emoji/apple/heart.png?v=15" title=":heart:" class="emoji" alt=":heart:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="318374" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-318374" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="318374"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #34"></div>
  </section>
</div>
    <div class="postbit" id="319408" data-post-id="319408">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="margarza" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  margarza
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hello! I am fairly new to the elixir language, so please bear with me <img src="https://forum.elixirforum.com/images/emoji/apple/folded_hands.png?v=15" title=":folded_hands:" class="emoji" alt=":folded_hands:" loading="lazy" width="20" height="20"><img src="https://forum.elixirforum.com/images/emoji/apple/folded_hands.png?v=15" title=":folded_hands:" class="emoji" alt=":folded_hands:" loading="lazy" width="20" height="20"></p>
<p>I have a question about the Req.Test module:</p>
<p>We are trying to test a method in case an API call fails with an status code of 404 and 500.</p>
<p>We have tried it with this code:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Req.Test.stub(:stub_req_plug, fn conn -&gt;
      conn
      |&gt; Plug.Conn.resp(404, "Not found")
      |&gt; Plug.Conn.send_resp()
    end)
</code></pre>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/up_arrow.png?v=15" title=":up_arrow:" class="emoji" alt=":up_arrow:" loading="lazy" width="20" height="20"> this returns <code>{:ok, "Not Found"}</code>, but we were wondering what we can do to get a return value of <code>{:error, reason}</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="319408" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-319408" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="319408"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #35"></div>
  </section>
</div>
    <div class="postbit" id="319410" data-post-id="319410">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachallaun" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/120/29208_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachallaun
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I believe you’re looking for the <a href="https://hexdocs.pm/req/Req.Steps.html#handle_http_errors/1" rel="noopener nofollow ugc"><code>handle_http_errors</code></a> step. It should look something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Req.get(test_endpoint, http_errors: :raise)
</code></pre>
<p>When you use the non-<code>!</code> variants (<code>get</code> as opposed to <code>get!</code>), this should result in the error tuple you’re looking for. When you use the <code>!</code> variant, it’ll raise the exception.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="319410" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-319410" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="319410"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #36"></div>
  </section>
</div>
    <div class="postbit" id="320402" data-post-id="320402">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wojtekmach" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wojtekmach/120/999_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wojtekmach
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Hex Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="zachallaun" data-post="37" data-topic="48494">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/48/29208_2.png" class="avatar"> zachallaun:</div>
<blockquote>
<p>this should result in the error tuple you’re looking for. When you use the <code>!</code> variant, it’ll raise the exception.</p>
</blockquote>
</aside>
<p><code>http_errors: :raise</code> <em>always</em> raises the exception. There were previous discussions of adding a non-raising variant that folks can find in the issue tracker.</p>
<aside class="quote no-group" data-username="margarza" data-post="36" data-topic="48494">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/e68b1a/48.png" class="avatar"> margarza:</div>
<blockquote>
<p>this returns <code>{:ok, "Not Found"}</code>, but we were wondering what we can do to get a return value of <code>{:error, reason}</code></p>
</blockquote>
</aside>
<p>This is not possible using the <code>:plug</code> option at the moment. My advice would be to start a real HTTP server using <a href="https://hexdocs.pm/bypass" class="inline-onebox" rel="noopener nofollow ugc">bypass v2.1.0 — Documentation</a> and simulate network failures using it. For example, you can set a low Req :receive_timeout and <code>Process.sleep(1000)</code> in your Bypass stub. Instead of setting <code>plug: ...</code> you’d be setting <code>url: ...</code> (usually <code>base_url: ...</code>). You can still use <code>Req.Test</code> module to stub out the <em>url</em>!</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># config/test.exs
config :myapp, req_options: [
  # you need latest Req for :base_url to accept a function
  base_url: fn -&gt; Req.Test.stub(:mystub) end
]

# some_test.exs
bypass = Bypass.open()
Req.Test.stub(:mystub, "http://localhost:#{bypass.port}")

Bypass.stub(bypass, fn conn -&gt;
  ...
end)
</code></pre>
<p>The easiest network failure to test for is :econnrefused which you can get by hitting a port that is not bound so for example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Req.Test.stub(:mystub, "http://localhost:9999")

assert MyApp.some_request() ==
         {:error, %Mint.TransportError{reason: :econnrefused}
</code></pre>
<p>Just a friendly reminder, if you are able to pass Req options down through all the layers, that’s preferred than going through Req.Test. For example:</p>
<pre data-code-wrap="diff"><code class="lang-diff">- Req.Test.stub(:mystub, "http://localhost:9999")
- 
- assert MyApp.some_request() ==
+ assert MyApp.some_request(req_options: [base_url: "http://localhost:9999"]) ==
           {:error, %Mint.TransportError{reason: :econnrefused}
</code></pre>
<p>In future version of Req we plan to support simulating transport errors in :plug, something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">plug = fn _conn -&gt;
  :econnrefused
end

assert Req.get(plug: plug) ==
         %Req.TransportError{reason: :econnrefused}
</code></pre>
<p>exact API TBD. Stay tuned!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="320402" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-320402" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="320402"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #37"></div>
  </section>
</div>
    <div class="postbit" id="323161" data-post-id="323161">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey <a class="mention" href="/u/wojtekmach" rel="nofollow">@wojtekmach</a></p>
<p>We are using the new test functionality and it works great. But we want to run a couple integration tests and we would like to disable the test plug for those tests.</p>
<p>Is there a simple way to ignore the specified plug? We do not control the Req instance in the test, so we do not want to pass that option. We want to avoid messing with Application.put_env in the test if possible. We would like to set a flag in the test process and have the plug “ignore itself” if possible.</p>
<p>I see that if a plug is defined, the adapter will be set to <code>run_plug/1</code>, so our plug will always be called. Is there a safe way to define a custom plug and fallback to Req.Test by default, but call <code>run_finch</code> if the flag is set ?</p>
<p>(everything happens in the same process as the test)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="323161" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-323161" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="323161"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #38"></div>
  </section>
</div>
    <div class="postbit" id="323163" data-post-id="323163">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wojtekmach" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wojtekmach/120/999_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wojtekmach
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Hex Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Req.Test.stub/1,2 can be used to stub <em>anything</em> so you could stub Req <em>options</em>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.MyClient do
  def new(options) do
    Req.new(...)
    |&gt; merge_test_options()
  end

  if Mix.env() == :test do
    defp merge_test_options(req) do
      Req.merge(req, plug: Req.Test.stub(__MODULE__))
    end
  else
    defp merge_test_options(req) do
      req
    end
  end
end

# test with stub:
Req.Test.stub(MyApp.MyClient, fn conn -&gt; ... end)

# integration test:
Req.Test.stub(MyApp.MyClient, nil)
</code></pre>
<p>When you set <code>plug: nil</code> it is as if you never set the option in the first place.</p>
<p>It’s a little bit ugly to change production code to accomodate tests like but I believe it is the most straighforward option. There could be more indirect ways I did not consider yet.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="323163" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-323163" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="323163"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #39"></div>
  </section>
</div>
    <div class="postbit" id="323164" data-post-id="323164">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’d like to avoid doing that if possible but if it is the only option then fine.</p>
<p>Thank you <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="323164" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/req-a-batteries-included-http-client-for-elixir/48494/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-323164" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="323164"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #40"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/48494/load_more?page=5">Load more posts (23 remaining)</a>
</div></template></turbo-stream>