Rust quick dev httpc – Fail fast with Cargo watch
One of my favourite YouTube coders is Jeremy Chone.
Rust Axum Full Course – Web Development
One thing I want to capture here, for my own use, so I have it ready to copy and paste is the “quick dev”
#![allow_unused]
use anyhow::Result;
#[tokio::test]
async fn quick_dev() -> Result<()>{
let hc = httpc_test::new_client("http://localhost:8080")?;
hc.do_get("/hello").await?.print().await?;
Ok(())
}
[dev-dependencies]
anyhow = "1"
httpc-test = "0.1.1"
├── src
│ └── main.rs
├── target
│ ├── CACHEDIR.TAG
│ ├── debug
│ └── tmp
└── tests
└── quick_dev.rs
Install cargo watch
cargo watch -q -c -w src/ -x run
cargo watch -q -c -w tests/ -x "test -q quick_dev -- --nocapture"
Query Params in Axum
Line 19 :
handler_hello(Query(params: HelloParams):Query<HelloParams>)
Be sure to add :
use axum::extract::Query;
TMUX – restore session on reboot
The cargo commands are quite a lot to remember so save your session in TMUX by adding the vim/nvim plugin to restore the session.
prefix ctrl s – save
prefix ctrl r – restore
My prefix is “ctrl a” but the standard prefix is “ctrl b”
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# for vim
set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'
set -g @plugin 'tmux-plugins/tmux-resurrect'
run-shell ~/clone/path/resurrect.tmux
tmux-resurrect : https://github.com/tmux-plugins/tmux-resurrect