You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the struct that implements StateData and StaticResponseExtender used for extracting variables out of the URI is defined with a tuple, the route returns with a code 400.
Example
#[derive(Resource, serde::Deserialize)]#[resource(update_device)]pubstructDeviceResource;#[derive(Debug,Deserialize,Clone,StateData,StaticResponseExtender)]pubstructDeviceID(String);// This compiles fine, but the handler returns 400// Replacing the above with this makes the handler return ok// #[derive(Debug, Deserialize, Clone, StateData, StaticResponseExtender)]// pub struct DeviceID {// id: String// }#[endpoint( uri = "update/:id", method = "Method::GET", params = false, body = false)]pubasyncfnupdate_device(id:DeviceID) -> Response{
log::info!("Got id: `{:?}`", id);Response::no_content()}
// Test used// This will fail when the struct is defined as above,// but it passes when the struct is defined with the `id` field#[test]fntest_device_update(){let test_server = TestServer::new(router()).unwrap();let response = test_server
.client().get("http://localhost:7878/device/update/omega1").perform().unwrap();assert_eq!(response.status(),StatusCode::NO_CONTENT);}
I'm not sure if this is intentional, but it's not very clear why it fails and if that's intended behavior or not.
The text was updated successfully, but these errors were encountered:
The struct you're defining is being used as a gotham PathExtractor which is automatically provided for all types that are Deserialize, StateData and StaticResponseExtender. When extracting a path, the deserialize implementation is provided with a map, in your case the equivalent of {"id": "omega1"}. If the deserialize implementation rejects this input, the route returns a 400. The problem is not your tuple struct but rather the auto-derived deserialize implementation for it.
If the struct that implements
StateData
andStaticResponseExtender
used for extracting variables out of the URI is defined with a tuple, the route returns with a code 400.Example
I'm not sure if this is intentional, but it's not very clear why it fails and if that's intended behavior or not.
The text was updated successfully, but these errors were encountered: