carllerche / tower-web

A fast, boilerplate free, web framework for Rust
MIT License
981 stars 51 forks source link

`not yet implemented` panic when parsing Json body #198

Closed fuchsnj closed 5 years ago

fuchsnj commented 5 years ago

Short error

thread 'tokio-runtime-worker-0' panicked at 'not yet implemented', /home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.6/src/extract/serde.rs:71:17

Relevant bits of code

#[derive(Clone)]
pub struct ApiServer {
    challenge: Arc<Mutex<Challenge>>,
}

impl_web! {
    impl ApiServer {

        #[post("/secret")]
        fn check_secret_submission(&self, submission: SecretSubmission) -> Result<&'static str, ()> {
            println!("Submission: {:#?}", submission);
            Ok("done")
        }
    }
}

pub fn run(bind_addr: &'static str, challenge: Arc<Mutex<Challenge>>) {
    let addr = bind_addr.parse().expect("Invalid address");
    println!("API Server listening on http://{}", addr);

    // A service builder is used to configure our service.
    ServiceBuilder::new()
        .resource(ApiServer { challenge })
        .run(&addr)
        .unwrap();
}

#[derive(Extract, Debug, Serialize, Deserialize)]
pub struct SecretSubmission {
    secret: String
}

Dependency versions:

tower-web = "0.3.6"
tokio = "0.1.17"
serde = "1.0.89"

I can provide a full stacktrace if needed.

Questions:

  1. Am I doing this right? I couldn't find an example for JSON input
  2. Is there a workaround / way to make this work now?
  3. How can I help improve this? Even if I did something wrong it shouldn't panic.
fuchsnj commented 5 years ago

Code that is panicking: https://github.com/carllerche/tower-web/blob/release-0.3.6/src/extract/serde.rs#L71

fuchsnj commented 5 years ago

ah, apparently the argument names are important. It's an easy fix, just change the argument name to body. Is a panic the expected behavior here?

0xpr03 commented 5 years ago

see also https://github.com/carllerche/tower-web/issues/183#issuecomment-468664818

fuchsnj commented 5 years ago

closing as a duplicate of https://github.com/carllerche/tower-web/issues/183