Use asynchronous api requests in conjunction with yew's suspense feature

Overview

crates.io docs

Yew API Hook

Use asynchronous api requests in conjunction with yew's suspense feature

Usage

#[function_component]
fn App() -> Html {
    html! {
        <Suspense fallback={html! { {"Loading.."} }}>
            <AsyncComponent />
        </Suspense>
    }
}

#[function_component]
fn AsyncComponent() -> HtmlResult {
    let data = use_api(requests::Fetch { id: 0 })?;

    match data {
        Ok(json) => Ok(html! { {format!("{:#?}", json)} }),
        Err(_) => Ok(html! { {"An error occured"} })
    }
}

mod requests {
    use yew_api_hook::prelude::*;

    type ApiResult = anyhow::Result<serde_json::Value>;

    #[derive(Clone, Debug, PartialEq)]
    pub struct Fetch {
        pub id: u64
    }

    #[async_trait(?Send)]
    impl Request for Fetch {
        type Error = anyhow::Error;
        type Output = serde_json::Value;

        async fn run(&self) -> ApiResult {
            // Use your favorite http or whatever implementation
            get(format!("/entity/{}", self.id)).await
        }
    }
}
You might also like...
A lightweight but incredibly powerful and feature-rich BitTorrent tracker. Supports UDP + HTTP(S) and a private tracker mode.

Torrust Tracker Project Description Torrust Tracker is a lightweight but incredibly powerful and feature-rich BitTorrent tracker made using Rust. Feat

Terminal based, feature rich, interactive SQL tool

datafusion-tui (dft) DataFusion-tui provides a feature rich terminal application, built with tui-rs, for using DataFusion (and eventually Ballista). I

Firefox used to have this feature a while back (from Firefox 11 to 46) and it is so good, that I feel it needs revival.
Firefox used to have this feature a while back (from Firefox 11 to 46) and it is so good, that I feel it needs revival.

3D WebPage Inspector By: Seanpm2001, Et; Al. Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af A

An abstract, safe, and concise color conversion library for rust nightly This requires the feature adt_const_params

colortypes A type safe color conversion library This crate provides many methods for converting between color types. Everything is implemented abstrac

Fast, minimal, feature-rich, extended formatting syntax for Rust!

Formatting Tools Fast, minimal, feature-rich, extended formatting syntax for Rust! Features include: Arbitrary expressions inside the formatting brace

Find potential unused enabled feature flags and prune them.
Find potential unused enabled feature flags and prune them.

Potential unused, enabled feature flag finder and pruner. This cargo tool allows you to find and prune enabled, but, potentially unused feature flags

A beautiful and feature-packed Apple Music CLI
A beautiful and feature-packed Apple Music CLI

am A beautiful and feature-packed Apple Music CLI! Written in Rust. Installation Nix (recommended) This GitHub repository contains a flake. Add github

An open source, programmed in rust, privacy focused tool for reading programming resources (like stackoverflow) fast, efficient and asynchronous from the terminal.

Falion An open source, programmed in rust, privacy focused tool for reading programming resources (like StackOverFlow) fast, efficient and asynchronou

High-performance asynchronous computation framework for system simulation

Asynchronix A high-performance asynchronous computation framework for system simulation. What is this? Warning: this page is at the moment mostly addr

Releases(v0.2.0)
Owner
Mara Schulke
Rust Developer @Hum-Systems
Mara Schulke
CLI program for sending one-off requests to the VTube Studio API

vtubestudio-cli (vts) CLI program for sending one-off requests to the VTube Studio API. It connects to the websocket, authenticates, performs one or t

null 2 Nov 24, 2021
Components of Fornjot that are no longer actively maintained. Pull requests still welcome!

Fornjot - Extra Components About These are extra components from the Fornjot repository, that are no longer actively maintained. Fornjot's goal was to

Hanno Braun 4 Jun 6, 2023
This is an example Nostr rust project to enable '402 Payment Required' responses for requests to paid content.

Nostr Paywall Example This is an example Nostr rust project to enable 402 Payment Required responses for requests to paid content. To prove payment, a

Blake Jakopovic 6 May 6, 2023
💫 This program allows you to do requests in Rust without reqwest !

Zapros ?? This program allows you to do requests in Rust without reqwest ! Usage : Get use crate::http_client::HttpClient; use crate::http_client::Htt

zqo 4 Aug 18, 2023
Track where Nixpkgs pull requests have reached.

nixpkgs-track Track where Nixpkgs pull requests have reached (is that update in nixpkgs-unstable yet??). Originally created as a local and reliable CL

uncenter 5 Sep 28, 2024
Api testing tool made with rust to use for api developement (Kind of Tui)

Api testing tool made with rust to use for api developement (Kind of Tui) This Rust project provides a simple yet powerful tool for making HTTP reques

Kythonlk 3 Feb 14, 2024
A library that creates a terminal-like window with feature-packed drawing of text and easy input handling. MIRROR.

BearLibTerminal provides a pseudoterminal window with a grid of character cells and a simple yet powerful API for flexible textual output and uncompli

Tommy Ettinger 43 Oct 31, 2022
An feature packed Google Tasks CLI written purely in Rust

rChore A feature packed unofficial Google Tasks CLI to boost your producitvity, written purely in Rust. ?? What is rChore? rChore is an unofficial Goo

Hemanth Krishna 41 Dec 24, 2022
🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

?? A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3

Christian Visintin 574 Jan 5, 2023
Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Tim Oram 1.2k Jan 2, 2023