expression

REST: retry only under an appropriate request contract

A transport failure may leave the client unsure whether the operation completed. Do not retry an unsafe operation automatically unless its contract makes repetition safe or the original is known not to have taken effect. This toy decision models only that prerequisite; real retry budgets, deadlines, authentication and failure categories also matter. Standalone synthetic example. Expected stdout (not executed): GET true POST false POST true Common mistake: Treating any header called an idempotency key as proof the server honors it.

Formal Syntax & Structure

rust syntaxrust
method semantics + documented replay guarantee

Working Example

Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    use axum::http::Method;    fn may_repeat(method: &Method, replay_guaranteed: bool) -> bool {        method.is_idempotent() || replay_guaranteed    }    for (m, guarantee) in [(Method::GET,false),(Method::POST,false),(Method::POST,true)] {        println!("{} {}", m, may_repeat(&m, guarantee));    }}
Rust Reference