TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

I built an online RSS reader with Rust and WebAssembly

8 pointsby huydotnetover 5 years ago

3 comments

huydotnetover 5 years ago
I built this as an experiment with Cloudflare&#x27;s Worker Script.<p>Here&#x27;s a bit behind this app.<p>- Frontend: Just few lines of code using Svelte<p>- Backend: a Worker Script using Rust, here&#x27;s how I do the RSS to JSON stuff:<p><pre><code> #[wasm_bindgen] pub fn parse(content: &amp;str) -&gt; String { let feed: Option&lt;rss::Channel&gt; = match content.parse::&lt;Feed&gt;().unwrap() { Feed::RSS(rss_feed) =&gt; Some(rss_feed), _ =&gt; None }; if feed.is_some() { let rss_feed = feed.unwrap(); let items: Vec&lt;serde_json::Value&gt; = rss_feed.items.iter().map(|item: &amp;rss::Item| { return json!({ &quot;title&quot;: item.title.as_ref(), &quot;link&quot;: item.link.as_ref(), &quot;date&quot;: item.pub_date.as_ref(), }); }).collect(); return json!({ &quot;feed&quot;: items }).to_string(); } return &quot;&quot;.to_string(); } </code></pre> The only overhead, I think, is the part that I have to actually write the code to fetch RSS content in JavaScript (worker.js), as fool as you can imagine:<p><pre><code> const url = request.url.match(&#x2F;url=(.*)&#x2F;); if (url &amp;&amp; url.length &gt; 1) { const feeds = url[1].split(&#x27;,&#x27;); let promises = feeds.map(async url =&gt; { const res = await fetch(url); const text = await res.text(); const json = JSON.parse(parse(text)); return json &amp;&amp; json.feed || []; }); let result = await Promise.all(promises); let combined = result.reduce((arr, feed) =&gt; { arr = arr.concat(feed); return arr; }, []); return new Response(JSON.stringify({ &quot;items&quot;: combined }), {status: 200, headers: { &#x27;Content-Type&#x27;: &#x27;application&#x2F;json&#x27; }}); } </code></pre> If network libraries such as `reqwest`, and some date parser libraries like `chrono` already supported WASM, I&#x27;d be able to skip this JS step for good.<p>Deployed on Cloudflare using Wrangler CLI, I&#x27;m still on my free plan, and I hope I won&#x27;t hit a 100k requests&#x2F;day limit anytime soon.
lostmsuover 5 years ago
It is cool, but it is not really an application in the expected sense. It is just a 2 stage RSS to HTML converter (e.g. RSS-&gt;JSON server, JSON-&gt;HTML client).<p>Not sure why not make just do RSS-&gt;HTML directly on the server.<p>Obviously, does not track read state or sync, or anything else basically.
rahuldottechover 5 years ago
This is neat! I&#x27;m definitely going to be making use of this :)
评论 #21103776 未加载
评论 #21103760 未加载