The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Create A Live Reload HTTP Terminal Client To Monitor axum Development In Rust

TODO: Pull subtitle into page object

The Code

Code
[package]
name = "axum_dev_watch"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = {version = "1", features = ["full"] }
axum = "0.6"

[dev-dependencies]
anyhow = "1"
httpc-test = "0.1.1"
Code
use anyhow::Result;

#[tokio::test]
async fn monitor() -> Result<()> {
    let client = httpc_test::new_client("http://localhost:8181")?;
    client.do_get("/").await?.print().await?;
    Ok(())
}

Code
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{response::Html, Router};
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let index_route = Router::new().route("/", get(index_handler));
    let addr = SocketAddr::from(([127, 0, 0, 1], 8181));
    axum::Server::bind(&addr)
        .serve(index_route.into_make_service())
        .await
        .unwrap();
}

async fn index_handler() -> impl IntoResponse {
    println!("Got request for /");
    Html("Hello, world")
}

The Usage

Code
cargo watch -q -c -x "test -q monitor -- --nocapture"
Code
cargo watch -q -c -w src/ -x run

The Example

When the monitor process runs, it'll produce output like:

pre_full_default_section

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Create A Live Reload HTTP Terminal Client To Monitor axum Development In Rust

I'm working on my cauldron web server. I found this cool way
to setup a terminal client that makes calls to it during
development that shows responses. It's super handy. No more 
manually refreshing a browser to see changes. 


-- h2

The Code

-- code
-- name: Cargo.toml

[package]
name = "axum_dev_watch"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = {version = "1", features = ["full"] }
axum = "0.6"

[dev-dependencies]
anyhow = "1"
httpc-test = "0.1.1"


-- code
-- name: tests/monitor.rs

use anyhow::Result;

#[tokio::test]
async fn monitor() -> Result<()> {
    let client = httpc_test::new_client("http://localhost:8181")?;
    client.do_get("/").await?.print().await?;
    Ok(())
}



-- code
-- name: src/main.rs

use axum::response::IntoResponse;
use axum::routing::get;
use axum::{response::Html, Router};
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let index_route = Router::new().route("/", get(index_handler));
    let addr = SocketAddr::from(([127, 0, 0, 1], 8181));
    axum::Server::bind(&addr)
        .serve(index_route.into_make_service())
        .await
        .unwrap();
}

async fn index_handler() -> impl IntoResponse {
    println!("Got request for /");
    Html("Hello, world")
}


-- h2

The Usage

-- code

cargo watch -q -c -x "test -q monitor -- --nocapture"


-- code

cargo watch -q -c -w src/ -x run



-- h2

The Example

When the monitor process runs, it'll produce output
like:

-- pre

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 1 test

=== Response for GET http://localhost:8181/
=> Status         : 200 OK OK
=> Headers        :
   content-type: text/html; charset=utf-8
   content-length: 12
   date: Thu, 07 Sep 2023 22:50:48 GMT
=> Response Body  :
Hello, world
===


test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s



-- notes

- I'm doing this with axum in this example. The tool 
is client side though. It can run against 
other backends as well.



-- ref
-- title: Rust Axum Full Course
-- subtitle: Jeremy Chone
-- url: https://www.youtube.com/watch?v=XZtlD_m59sM


-- categories
-- Rust 
-- axum 

-- metadata
-- date: 2023-09-07 18:33:40
-- id: 2v5vebou
-- site: aws
-- type: post
-- status: draft