juniper/hyper/client/index.html
Juniper Documentation Builder 95d942c9d4 Update documentation for Juniper
2016-09-11 18:41:24 +00:00

232 lines
No EOL
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `client` mod in crate `hyper`.">
<meta name="keywords" content="rust, rustlang, rust-lang, client">
<title>hyper::client - Rust</title>
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'><a href='../index.html'>hyper</a></p><script>window.sidebarCurrent = {name: 'client', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content mod">
<h1 class='fqn'><span class='in-band'>Module <a href='../index.html'>hyper</a>::<wbr><a class='mod' href=''>client</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a id='src-108' class='srclink' href='../../src/hyper/client/mod.rs.html#1-644' title='goto source code'>[src]</a></span></h1>
<div class='docblock'><p>HTTP Client</p>
<h1 id='usage' class='section-header'><a href='#usage'>Usage</a></h1>
<p>The <code>Client</code> API is designed for most people to make HTTP requests.
It utilizes the lower level <code>Request</code> API.</p>
<h2 id='get' class='section-header'><a href='#get'>GET</a></h2>
<pre class='rust rust-example-rendered'>
<span class='kw'>let</span> <span class='ident'>client</span> <span class='op'>=</span> <span class='ident'>Client</span>::<span class='ident'>new</span>();
<span class='kw'>let</span> <span class='ident'>res</span> <span class='op'>=</span> <span class='ident'>client</span>.<span class='ident'>get</span>(<span class='string'>&quot;http://example.domain&quot;</span>).<span class='ident'>send</span>().<span class='ident'>unwrap</span>();
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>res</span>.<span class='ident'>status</span>, <span class='ident'>hyper</span>::<span class='prelude-val'>Ok</span>);</pre>
<p>The returned value is a <code>Response</code>, which provides easy access to
the <code>status</code>, the <code>headers</code>, and the response body via the <code>Read</code>
trait.</p>
<h2 id='post' class='section-header'><a href='#post'>POST</a></h2>
<pre class='rust rust-example-rendered'>
<span class='kw'>let</span> <span class='ident'>client</span> <span class='op'>=</span> <span class='ident'>Client</span>::<span class='ident'>new</span>();
<span class='kw'>let</span> <span class='ident'>res</span> <span class='op'>=</span> <span class='ident'>client</span>.<span class='ident'>post</span>(<span class='string'>&quot;http://example.domain&quot;</span>)
.<span class='ident'>body</span>(<span class='string'>&quot;foo=bar&quot;</span>)
.<span class='ident'>send</span>()
.<span class='ident'>unwrap</span>();
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>res</span>.<span class='ident'>status</span>, <span class='ident'>hyper</span>::<span class='prelude-val'>Ok</span>);</pre>
<h1 id='sync' class='section-header'><a href='#sync'>Sync</a></h1>
<p>The <code>Client</code> implements <code>Sync</code>, so you can share it among multiple threads
and make multiple requests simultaneously.</p>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>sync</span>::<span class='ident'>Arc</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>thread</span>;
<span class='comment'>// Note: an Arc is used here because `thread::spawn` creates threads that</span>
<span class='comment'>// can outlive the main thread, so we must use reference counting to keep</span>
<span class='comment'>// the Client alive long enough. Scoped threads could skip the Arc.</span>
<span class='kw'>let</span> <span class='ident'>client</span> <span class='op'>=</span> <span class='ident'>Arc</span>::<span class='ident'>new</span>(<span class='ident'>Client</span>::<span class='ident'>new</span>());
<span class='kw'>let</span> <span class='ident'>clone1</span> <span class='op'>=</span> <span class='ident'>client</span>.<span class='ident'>clone</span>();
<span class='kw'>let</span> <span class='ident'>clone2</span> <span class='op'>=</span> <span class='ident'>client</span>.<span class='ident'>clone</span>();
<span class='ident'>thread</span>::<span class='ident'>spawn</span>(<span class='kw'>move</span> <span class='op'>||</span> {
<span class='ident'>clone1</span>.<span class='ident'>get</span>(<span class='string'>&quot;http://example.domain&quot;</span>).<span class='ident'>send</span>().<span class='ident'>unwrap</span>();
});
<span class='ident'>thread</span>::<span class='ident'>spawn</span>(<span class='kw'>move</span> <span class='op'>||</span> {
<span class='ident'>clone2</span>.<span class='ident'>post</span>(<span class='string'>&quot;http://example.domain/post&quot;</span>).<span class='ident'>body</span>(<span class='string'>&quot;foo=bar&quot;</span>).<span class='ident'>send</span>().<span class='ident'>unwrap</span>();
});</pre>
</div><h2 id='reexports' class='section-header'><a href="#reexports">Reexports</a></h2>
<table><tr><td><code>pub use self::<a class='mod'
href='./pool/index.html'>pool</a>::<a class='struct' href='../../hyper/client/pool/struct.Pool.html' title='hyper::client::pool::Pool'>Pool</a>;</code></td></tr><tr><td><code>pub use self::<a class='mod'
href='./request/index.html'>request</a>::<a class='struct' href='../../hyper/client/request/struct.Request.html' title='hyper::client::request::Request'>Request</a>;</code></td></tr><tr><td><code>pub use self::<a class='mod'
href='./response/index.html'>response</a>::<a class='struct' href='../../hyper/client/response/struct.Response.html' title='hyper::client::response::Response'>Response</a>;</code></td></tr></table><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class='mod' href='pool/index.html'
title='hyper::client::pool'>pool</a></td>
<td class='docblock short'>
<p>Client Connection Pooling</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='mod' href='request/index.html'
title='hyper::client::request'>request</a></td>
<td class='docblock short'>
<p>Client Requests</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='mod' href='response/index.html'
title='hyper::client::response'>response</a></td>
<td class='docblock short'>
<p>Client Responses</p>
</td>
</tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr class=' module-item'>
<td><a class='struct' href='struct.Client.html'
title='hyper::client::Client'>Client</a></td>
<td class='docblock short'>
<p>A Client to use additional features with Requests.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.ProxyConfig.html'
title='hyper::client::ProxyConfig'>ProxyConfig</a></td>
<td class='docblock short'>
<p>Proxy server configuration with a custom TLS wrapper.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='struct' href='struct.RequestBuilder.html'
title='hyper::client::RequestBuilder'>RequestBuilder</a></td>
<td class='docblock short'>
<p>Options for an individual Request.</p>
</td>
</tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table>
<tr class=' module-item'>
<td><a class='enum' href='enum.Body.html'
title='hyper::client::Body'>Body</a></td>
<td class='docblock short'>
<p>An enum of possible body types for a Request.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='enum' href='enum.RedirectPolicy.html'
title='hyper::client::RedirectPolicy'>RedirectPolicy</a></td>
<td class='docblock short'>
<p>Behavior regarding how to handle redirects within a Client.</p>
</td>
</tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
<table>
<tr class=' module-item'>
<td><a class='trait' href='trait.IntoUrl.html'
title='hyper::client::IntoUrl'>IntoUrl</a></td>
<td class='docblock short'>
<p>A helper trait to convert common objects into a Url.</p>
</td>
</tr></table></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "hyper";
window.playgroundUrl = "";
</script>
<script src="../../jquery.js"></script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>