expression
REST: test old and new request contracts together
Backward compatibility is directional. An old request should continue to work on a compatible new server, but a new request using new features may not work on an old server. The example deliberately models a strict older parser; it illustrates rollout order, not actual deployment testing. Standalone synthetic example. Expected stdout (not executed): old -> new: true new -> old: false new -> new: true Common mistake: Testing only the newest client and server pair before a rolling deployment.
Formal Syntax & Structure
rust syntaxrust
old input × new server; new input × old serverWorking 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() { #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct Old { name: String } #[derive(Deserialize)] struct New { name: String, #[serde(default)] urgent: bool } let old = r#"{"name":"pen"}"#; let new = r#"{"name":"pen","urgent":true}"#; println!("old -> new: {}", serde_json::from_str::<New>(old).is_ok()); println!("new -> old: {}", serde_json::from_str::<Old>(new).is_ok()); println!("new -> new: {}", serde_json::from_str::<New>(new).is_ok());}