Giter Site home page Giter Site logo

mikemoolenaar / rath-stack Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 363 KB

The RATH stack (Rust + Axum + Turso + HTMX) for building web apps

Home Page: https://rust-api-plus-htmx.fly.dev

License: MIT License

Rust 64.25% HTML 26.46% JavaScript 0.95% Shell 2.80% CSS 1.80% Dockerfile 3.21% TypeScript 0.52%
axum-server htmx rust turso

rath-stack's People

Contributors

mikemoolenaar avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

rath-stack's Issues

Connection as shared state causes error after idle without requests

Hi. I found this repo searching for example using turso and axum. I've done some testing and found that using a Connection that is shared as State results in errors after a some successful requests if there's a pause.

called `Result::unwrap()` on an `Err` value: Hrana(Api("{\"message\":\"The stream has expired due to inactivity\",\"code\":\"STREAM_EXPIRED\"}"))

Here's what I tested.
main.rs

let url = env::var("LIBSQL_URL").expect("LIBSQL_URL must be set");
let token = env::var("LIBSQL_AUTH_TOKEN").expect("LIBSQL auth token must be set");

let db = Builder::new_remote(url, token).build().await.unwrap();
let conn = db.connect().unwrap();

let app = Router::new()
        .merge(user::show())
        .with_state(Arc::new(AppState {conn}));
let address = format!("127.0.0.1:{}", 3000).parse().unwrap()
let listener = tokio::net::TcpListener::bind(address).await.unwrap();
let svc = app.into_make_service_with_connect_info::<SocketAddr>();
axum::serve(listener, svc).await.unwrap();

file with user route

pub async fn show_user(
    Path(user_id): Path<String>,
    State(app): State<Arc<AppState>>
) -> String {
    let conn = &app.conn;
    let mut stmt = conn
        .prepare("SELECT * FROM users WHERE id = ?1")
        .await
        .unwrap();
    let row = stmt.query_row([user_id.as_str()]).await.unwrap();
    let id = row.get_value(1).unwrap().as_text().unwrap().clone();
    id
}

Worth noting Turso has an example over here: https://docs.turso.tech/sdk/rust/guides/axum
They construct both the DB and the connection in the handler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.