mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
60 lines
13 KiB
HTML
60 lines
13 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="`awc` is an asynchronous HTTP and WebSocket client library."><title>awc - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="awc" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../awc/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../awc/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../awc/index.html">awc</a><span class="version">3.5.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#types">Type Aliases</a></li></ul></section></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">awc</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../src/awc/lib.rs.html#1-150">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>awc</code> is an asynchronous HTTP and WebSocket client library.</p>
|
||
<h2 id="get-requests"><a class="doc-anchor" href="#get-requests">§</a><code>GET</code> Requests</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// create client
|
||
</span><span class="kw">let </span><span class="kw-2">mut </span>client = awc::Client::default();
|
||
|
||
<span class="comment">// construct request
|
||
</span><span class="kw">let </span>req = client.get(<span class="string">"http://www.rust-lang.org"</span>)
|
||
.insert_header((<span class="string">"User-Agent"</span>, <span class="string">"awc/3.0"</span>));
|
||
|
||
<span class="comment">// send request and await response
|
||
</span><span class="kw">let </span>res = req.send().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
<span class="macro">println!</span>(<span class="string">"Response: {:?}"</span>, res);</code></pre></div>
|
||
<h2 id="post-requests"><a class="doc-anchor" href="#post-requests">§</a><code>POST</code> Requests</h2><h3 id="raw-body"><a class="doc-anchor" href="#raw-body">§</a>Raw Body</h3>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>client = awc::Client::default();
|
||
<span class="kw">let </span>response = client.post(<span class="string">"http://httpbin.org/post"</span>)
|
||
.send_body(<span class="string">"Raw body contents"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||
<h3 id="json"><a class="doc-anchor" href="#json">§</a>JSON</h3>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>request = <span class="macro">serde_json::json!</span>({
|
||
<span class="string">"lang"</span>: <span class="string">"rust"</span>,
|
||
<span class="string">"body"</span>: <span class="string">"json"
|
||
</span>});
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>client = awc::Client::default();
|
||
<span class="kw">let </span>response = client.post(<span class="string">"http://httpbin.org/post"</span>)
|
||
.send_json(<span class="kw-2">&</span>request)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||
<h3 id="url-encoded-form"><a class="doc-anchor" href="#url-encoded-form">§</a>URL Encoded Form</h3>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>params = [(<span class="string">"foo"</span>, <span class="string">"bar"</span>), (<span class="string">"baz"</span>, <span class="string">"quux"</span>)];
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>client = awc::Client::default();
|
||
<span class="kw">let </span>response = client.post(<span class="string">"http://httpbin.org/post"</span>)
|
||
.send_form(<span class="kw-2">&</span>params)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
|
||
<h2 id="response-compression"><a class="doc-anchor" href="#response-compression">§</a>Response Compression</h2>
|
||
<p>All <a href="https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding">official</a> and common content encoding codecs are supported, optionally.</p>
|
||
<p>The <code>Accept-Encoding</code> header will automatically be populated with enabled codecs and added to
|
||
outgoing requests, allowing servers to select their <code>Content-Encoding</code> accordingly.</p>
|
||
<p>Feature flags enable these codecs according to the table below. By default, all <code>compress-*</code>
|
||
features are enabled.</p>
|
||
<div><table><thead><tr><th>Feature</th><th>Codecs</th></tr></thead><tbody>
|
||
<tr><td><code>compress-brotli</code></td><td>brotli</td></tr>
|
||
<tr><td><code>compress-gzip</code></td><td>gzip, deflate</td></tr>
|
||
<tr><td><code>compress-zstd</code></td><td>zstd</td></tr>
|
||
</tbody></table>
|
||
</div><h2 id="websockets"><a class="doc-anchor" href="#websockets">§</a>WebSockets</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures_util::{SinkExt <span class="kw">as _</span>, StreamExt <span class="kw">as _</span>};
|
||
|
||
<span class="kw">let </span>(_resp, <span class="kw-2">mut </span>connection) = awc::Client::new()
|
||
.ws(<span class="string">"ws://echo.websocket.org"</span>)
|
||
.connect()
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
connection
|
||
.send(awc::ws::Message::Text(<span class="string">"Echo"</span>.into()))
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let </span>response = connection.next().<span class="kw">await</span>.unwrap()<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq!</span>(response, awc::ws::Frame::Text(<span class="string">"Echo"</span>.into()));</code></pre></div>
|
||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.cookie"><code>pub use <a class="mod" href="https://docs.rs/cookie/0.16/cookie/index.html" title="mod cookie">cookie</a>;</code></div><div class="desc docblock-short"><span class="stab portability" title="Available on crate feature `cookies` only"><code>cookies</code></span></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="body/index.html" title="mod awc::body">body</a></div><div class="desc docblock-short">Traits and structures to aid consuming and writing HTTP payloads.</div></li><li><div class="item-name"><a class="mod" href="error/index.html" title="mod awc::error">error</a></div><div class="desc docblock-short">HTTP client errors</div></li><li><div class="item-name"><a class="mod" href="http/index.html" title="mod awc::http">http</a></div><div class="desc docblock-short">Various HTTP related types.</div></li><li><div class="item-name"><a class="mod" href="middleware/index.html" title="mod awc::middleware">middleware</a></div></li><li><div class="item-name"><a class="mod" href="test/index.html" title="mod awc::test">test</a></div><div class="desc docblock-short">Test helpers for actix http client to use during testing.</div></li><li><div class="item-name"><a class="mod" href="ws/index.html" title="mod awc::ws">ws</a></div><div class="desc docblock-short">Websockets client</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Client.html" title="struct awc::Client">Client</a></div><div class="desc docblock-short">An asynchronous HTTP and WebSocket client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientBuilder.html" title="struct awc::ClientBuilder">ClientBuilder</a></div><div class="desc docblock-short">An HTTP Client builder</div></li><li><div class="item-name"><a class="struct" href="struct.ClientRequest.html" title="struct awc::ClientRequest">ClientRequest</a></div><div class="desc docblock-short">An HTTP Client request builder</div></li><li><div class="item-name"><a class="struct" href="struct.ClientResponse.html" title="struct awc::ClientResponse">ClientResponse</a></div><div class="desc docblock-short">Client Response</div></li><li><div class="item-name"><a class="struct" href="struct.Connect.html" title="struct awc::Connect">Connect</a></div></li><li><div class="item-name"><a class="struct" href="struct.Connector.html" title="struct awc::Connector">Connector</a></div><div class="desc docblock-short">Manages HTTP client network connectivity.</div></li><li><div class="item-name"><a class="struct" href="struct.FrozenClientRequest.html" title="struct awc::FrozenClientRequest">FrozenClientRequest</a></div><div class="desc docblock-short"><code>FrozenClientRequest</code> struct represents cloneable client request.</div></li><li><div class="item-name"><a class="struct" href="struct.FrozenSendBuilder.html" title="struct awc::FrozenSendBuilder">FrozenSendBuilder</a></div><div class="desc docblock-short">Builder that allows to modify extra headers.</div></li><li><div class="item-name"><a class="struct" href="struct.JsonBody.html" title="struct awc::JsonBody">JsonBody</a></div><div class="desc docblock-short">A <code>Future</code> that reads a body stream, parses JSON, resolving to a deserialized <code>T</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.ResponseBody.html" title="struct awc::ResponseBody">ResponseBody</a></div><div class="desc docblock-short">A <code>Future</code> that reads a body stream, resolving as [<code>Bytes</code>].</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.ConnectRequest.html" title="enum awc::ConnectRequest">ConnectRequest</a></div><div class="desc docblock-short">Combined HTTP and WebSocket request type received by connection service.</div></li><li><div class="item-name"><a class="enum" href="enum.ConnectResponse.html" title="enum awc::ConnectResponse">ConnectResponse</a></div><div class="desc docblock-short">Combined HTTP response & WebSocket tunnel type returned from connection service.</div></li><li><div class="item-name"><a class="enum" href="enum.SendClientRequest.html" title="enum awc::SendClientRequest">SendClientRequest</a></div><div class="desc docblock-short">Future that sends request’s payload and resolves to a server response.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.BoxConnectorService.html" title="type awc::BoxConnectorService">BoxConnectorService</a></div></li><li><div class="item-name"><a class="type" href="type.BoxedSocket.html" title="type awc::BoxedSocket">BoxedSocket</a></div></li><li><div class="item-name"><a class="type" href="type.MessageBody.html" title="type awc::MessageBody">MessageBody</a><span class="stab deprecated" title="">Deprecated</span></div></li></ul></section></div></main></body></html> |