1
0
card/public/book/1/AGlkOnBsYzo0aHFqZm43bTZuNWhubzNkb2FtdWhnZWY/c3/3.html
2024-03-23 05:22:55 +09:00

624 lines
18 KiB
HTML

<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>reqwest · hello world! bluesky</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="@gitbook-ng/gitbook 3.3.6">
<meta name="author" content="syui">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-codeblock-filename/block.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../c4/" />
<link rel="prev" href="2.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
hello world! bluesky
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../c1/">
<a href="../c1/">
part 1
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../c1/1.html">
<a href="../c1/1.html">
quick start
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../c1/2.html">
<a href="../c1/2.html">
example
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="../c2/">
<a href="../c2/">
part 2
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="../c2/1.html">
<a href="../c2/1.html">
bluesky
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="../c2/2.html">
<a href="../c2/2.html">
terminal
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="../c2/3.html">
<a href="../c2/3.html">
shell
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="../c2/4.html">
<a href="../c2/4.html">
rust
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="./">
<a href="./">
part 3
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="1.html">
<a href="1.html">
hello world
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="2.html">
<a href="2.html">
seahorse
</a>
</li>
<li class="chapter active" data-level="1.4.3" data-path="3.html">
<a href="3.html">
reqwest
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="../c4/">
<a href="../c4/">
part 4
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../c4/0.html">
<a href="../c4/0.html">
ai
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../c4/1.html">
<a href="../c4/1.html">
config
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../c4/2.html">
<a href="../c4/2.html">
mention
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../c4/3.html">
<a href="../c4/3.html">
base64
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="../end/">
<a href="../end/">
end
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >reqwest</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h3 id="reqwest">reqwest</h3>
<p>Before explaining <a href="https://github.com/seanmonstar/reqwest" target="_blank">seanmonstar/reqwest</a> in RUST, try the following command.</p>
<pre><code class="lang-sh">$ curl <span class="hljs-_">-s</span>L <span class="hljs-string">&quot;https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=support.bsky.team&amp;collection=app.bsky.feed.post&quot;</span>
</code></pre>
<p>This hits the api to get the timeline for <a href="https://bsky.app/profile/did:plc:oc6vwdlmk2kqyida5i74d3p5" target="_blank">support.bsky.social</a>.</p>
<p>You can understand that <code>reqwest</code> is mainly a rust lib to hit the api.</p>
<p>Now, let&apos;s write the actual code.</p>
<div><p class="code-filename">Cargo.toml</p></div>
<pre><code class="lang-toml"><span class="hljs-section">[package]</span>
<span class="hljs-attr">name</span> = <span class="hljs-string">&quot;rust&quot;</span>
<span class="hljs-attr">version</span> = <span class="hljs-string">&quot;0.1.0&quot;</span>
<span class="hljs-attr">edition</span> = <span class="hljs-string">&quot;2021&quot;</span>
<span class="hljs-section">
[dependencies]</span>
<span class="hljs-attr">seahorse</span> = <span class="hljs-string">&quot;*&quot;</span>
<span class="hljs-attr">reqwest</span> = <span class="hljs-string">&quot;*&quot;</span>
<span class="hljs-attr">tokio</span> = { version = <span class="hljs-string">&quot;1&quot;</span>, features = [<span class="hljs-string">&quot;full&quot;</span>] }
</code></pre>
<pre><code class="lang-src/main.rs">use seahorse::{App, Context, Command};
use std::env;
fn main() {
let args: Vec&lt;String&gt; = env::args().collect();
let app = App::new(env!(&quot;CARGO_PKG_NAME&quot;))
.action(s)
.command(
Command::new(&quot;yes&quot;)
.alias(&quot;y&quot;)
.action(y),
)
.command(
Command::new(&quot;no&quot;)
.alias(&quot;n&quot;)
.action(n),
)
.command(
Command::new(&quot;test&quot;)
.alias(&quot;t&quot;)
.action(|c| println!(&quot;Hello, {:?}&quot;, c.args)),
)
.command(
Command::new(&quot;bluesky&quot;)
.alias(&quot;b&quot;)
.action(c_list_records),
)
;
app.run(args);
}
fn s(_c: &amp;Context) {
println!(&quot;Hello, world!&quot;);
}
fn y(_c: &amp;Context) {
println!(&quot;yes&quot;);
}
fn n(_c: &amp;Context) {
println!(&quot;no&quot;);
}
#[tokio::main]
async fn list_records() -&gt; reqwest::Result&lt;()&gt; {
let client = reqwest::Client::new();
let handle= &quot;support.bsky.team&quot;;
let col = &quot;app.bsky.feed.post&quot;;
let body = client.get(&quot;https://bsky.social/xrpc/com.atproto.repo.listRecords&quot;)
.query(&amp;[(&quot;repo&quot;, &amp;handle),(&quot;collection&quot;, &amp;col)])
.send()
.await?
.text()
.await?;
println!(&quot;{}&quot;, body);
Ok(())
}
fn c_list_records(_c: &amp;Context) {
list_records().unwrap();
}
</code></pre>
<p>This is then <code>cargo build</code> and run the command as usual.</p>
<pre><code class="lang-sh">$ ./target/debug/rust b
</code></pre>
<p>The following is an <code>example</code>, i.e., code with useless command options removed.</p>
<p>The main points of the code are as follows.</p>
<pre><code class="lang-src/main.rs">.command(
Command::new(&quot;bluesky&quot;)
.alias(&quot;b&quot;)
.action(c_list_records),
)
#[tokio::main]
async fn list_records() -&gt; reqwest::Result&lt;()&gt; {
let client = reqwest::Client::new();
let handle= &quot;support.bsky.team&quot;;
let col = &quot;app.bsky.feed.post&quot;;
let body = client.get(&quot;https://bsky.social/xrpc/com.atproto.repo.listRecords&quot;)
.query(&amp;[(&quot;repo&quot;, &amp;handle),(&quot;collection&quot;, &amp;col)])
.send()
.await?
.text()
.await?;
println!(&quot;{}&quot;, body);
Ok(())
}
fn c_list_records(_c: &amp;Context) {
list_records().unwrap();
}
</code></pre>
<h4 id="query">query</h4>
<p>Try adding <code>query</code>. Now the output will be on one line and in order of oldest to newest.</p>
<div><p class="code-filename">src/main.rs</p></div>
<pre><code class="lang-rust">async <span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">list_records</span></span>() -&gt; reqwest::<span class="hljs-built_in">Result</span>&lt;()&gt; {
<span class="hljs-keyword">let</span> client = reqwest::Client::new();
<span class="hljs-keyword">let</span> handle= <span class="hljs-string">&quot;support.bsky.team&quot;</span>;
<span class="hljs-keyword">let</span> col = <span class="hljs-string">&quot;app.bsky.feed.post&quot;</span>;
<span class="hljs-keyword">let</span> body = client.get(<span class="hljs-string">&quot;https://bsky.social/xrpc/com.atproto.repo.listRecords&quot;</span>)
<span class="hljs-comment">//.query(&amp;[(&quot;repo&quot;, &amp;handle),(&quot;collection&quot;, &amp;col)])</span>
.query(&amp;[(<span class="hljs-string">&quot;repo&quot;</span>, &amp;handle),(<span class="hljs-string">&quot;collection&quot;</span>, &amp;col),(<span class="hljs-string">&quot;limit&quot;</span>, &amp;<span class="hljs-string">&quot;1&quot;</span>),(<span class="hljs-string">&quot;revert&quot;</span>, &amp;<span class="hljs-string">&quot;true&quot;</span>)])
.send()
.await?
.text()
.await?;
<span class="hljs-built_in">println!</span>(<span class="hljs-string">&quot;{}&quot;</span>, body);
<span class="hljs-literal">Ok</span>(())
}
</code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="2.html" class="navigation navigation-prev " aria-label="Previous page: seahorse">
<i class="fa fa-angle-left"></i>
</a>
<a href="../c4/" class="navigation navigation-next " aria-label="Next page: part 4">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"reqwest","level":"1.4.3","depth":2,"next":{"title":"part 4","level":"1.5","depth":1,"path":"c4/README.md","ref":"c4/README.md","articles":[{"title":"ai","level":"1.5.1","depth":2,"path":"c4/0.md","ref":"c4/0.md","articles":[]},{"title":"config","level":"1.5.2","depth":2,"path":"c4/1.md","ref":"c4/1.md","articles":[]},{"title":"mention","level":"1.5.3","depth":2,"path":"c4/2.md","ref":"c4/2.md","articles":[]},{"title":"base64","level":"1.5.4","depth":2,"path":"c4/3.md","ref":"c4/3.md","articles":[]}]},"previous":{"title":"seahorse","level":"1.4.2","depth":2,"path":"c3/2.md","ref":"c3/2.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","codeblock-filename","mermaid-gb3","diff"],"root":"./","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"codeblock-filename":{},"mermaid-gb3":{},"diff":{"type":"markdown","method":"diffChars","options":{}},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"syui","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"hello world! bluesky","gitbook":"*","description":"This is a bluesky ai-card example, and first rust"},"file":{"path":"c3/3.md","mtime":"2023-07-31T07:01:29.133Z","type":"markdown"},"gitbook":{"version":"3.3.6","time":"2023-07-31T07:16:09.509Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>