2

I am attempting to write a simple api with rocket to help myself learn rust but I have run into this error after I attempted declaring a POST route:

error: malformed attribute
  --> src/main.rs:26:1
   |
26 | #[post("/producers", format="application/json", data =<"prod">)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: expected syntax: #[post(key = value, ..)]

Here is the function declaration for that route:

#[post("/producers", format="application/json", data =<"producer">)]
fn post_producer(producer: Json<Producer>) -> String {
    return("hello".to_string());
}

And I am importing these macros:

#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate rocket_contrib;

use rocket_contrib::json::Json;

I have another method declared for GET but that one works fine. I've done some research and found these examples and documentation: https://api.rocket.rs/v0.4/rocket_codegen/attr.post.html https://rocket.rs/v0.4/guide/requests/#format

As far as I can tell I am following the conventions mentioned in both of those pages and I'm a bit lost on where to go from here. Is there some bit of syntax or an import that I'm missing?

ruffles
  • 23
  • 3
  • Why do you have angle brackets around `<"application/json">` and `<"prod">`? – Jmb Feb 20 '20 at 15:53
  • It's a requirement for parameters. It's not a requirement for the `format` field, I'll edit that out quick. – ruffles Feb 20 '20 at 16:36

1 Answers1

1

According to the documentation, the data parameter must have the <> inside of the quotation marks. So data="<prod>" should fix the issue.