expression
REST: model collections and resource identity
A collection URI identifies a group of resources; a member URI identifies one item. Keep the public identifier independent of display names and internal storage positions. This synthetic lookup returns 404 for an absent ID, not an empty successful item. Plural nouns are a naming convention, not a protocol requirement. Standalone synthetic example. Expected stdout (not executed): 200 404 Common mistake: Using a mutable display name as the permanent identifier.
Formal Syntax & Structure
rust syntaxrust
GET /items/{id}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::{extract::Path, routing::get}; async fn item(Path(id): Path<u32>) -> Result<Json<serde_json::Value>, StatusCode> { if id == 7 { Ok(Json(serde_json::json!({"id":7,"name":"pen"}))) } else { Err(StatusCode::NOT_FOUND) } } let app = Router::new().route("/items/{id}", get(item)); for uri in ["/items/7", "/items/8"] { let res = app.clone().oneshot(Request::builder().uri(uri).body(Body::empty()).unwrap()).await.unwrap(); println!("{}", res.status().as_u16()); }}