我对生锈完全陌生。我正在尝试用 Rocket 创建一个非常简单的 API。我的以下路线不起作用,我不知道为什么。
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use rocket_contrib::json::Json;
use serde::{Serialize, Deserialize};
use serde_json::Result as JsonResult;
#[derive(Serialize, Deserialize)]
struct Article {
id: usize,
title: String,
body: String,
}
#[post("/new", format = "application/json", data = "<article>")]
fn create_article (article: Json<Article>) -> JsonResult<()> {
println!("Article is: id:{}, title:{}, body:{}", article.id, article.title, article.body);
Ok(())
}
fn main() {
rocket::ignite()
.mount("/article", routes![create_article])
.launch();
}
当我发送请求时,我有以下内容:
POST /article/new?id=1&title=titre&body=corps application/json:
=> Matched: POST /article/new (create_article)
=> Warning: Form data does not have form content type.
=> Outcome: Forward
=> Error: No matching routes for POST /article/new?id=1&title=titre&body=corps application/json.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
有人能帮我吗 ?