poem
poem copied to clipboard
poem_openapi post request with form data always returns 400
Expected Behavior
A normal response
Actual Behavior
see title
Steps to Reproduce the Problem
Set up something along the lines of
#[poem_openapi::OpenApi]
impl Api {
#[oai(path = "/items", method = "post")]
async fn get_items_f(&self, data : Form<IdsRequest>) -> Json<Vec<&Item>> {
Json(vec![]) // empty dummy response
}
}
#[derive(Debug, serde::Deserialize, poem_openapi::Object)]
struct IdsRequest {
pub ids : Vec<u32>
}
// dummy return object
#[derive(Debug, poem_openapi::Object)] struct Item { }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_service = poem_openapi::OpenApiService::new(Api, "API", "0.0.0")
.server("http://localhost:3000");
let route = poem::Route::new().nest("/", api_endpoint);
poem::Server::new(poem::listener::TcpListener::bind("127.0.0.1:3000")).run(route).await?;
Ok(())
}
Disclaimer: This is taken in chunks form a much larger project and therefore might not actually compile like this although it looks good to me.
If you now send an request to this (for example with
curl -X 'POST' \
'http://localhost:3000/items' \
-H 'accept: application/json; charset=utf-8' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'ids=14214'
) it will just spit back a 400 error.
Ive tried playing around with tracing_subscriber
and the Tracing
middleware, but to no avail.
Hopefully you can make something of this.
I also want to add that i couldn't find an official example for how to even use the Form wrapper, so this might just be a case of user error.
Specifications
- Version:
poem = "1.3.58"
;poem-openapi = 3.0.5
- Platform:
Win10-x86_64
(uncertain if it affects others aswell, but likely) - Subsystem:
poem-openapi
I don't recommend you to use Form
type in Poem-openapi
, because it is currently not well supported, I will improve it later. 🙂
Ah, very well. Maybe you should add a disclaimer to it for now? Either way, thank you for the quick response ^^