0

Postman を使用して Rust API に POST リクエストを送信しようとしています。

#![feature(proc_macro_hygiene, decl_macro)]

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

use rocket_contrib::json::{Json, JsonValue};

#[derive(Serialize, Deserialize)]
struct Response {
    status: String,
}

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[post("/register", format = "json", data = "<register>")]
fn user_create(register: Json<Response>) -> Json<Response> {
    Json(Response {
        status: "works".to_string(),
    })
}

fn main() {
    rocket::ignite()
        .mount("/", routes![index, user_create])
        .launch();
}

Cargo.toml:

[package]
name = "hello-rocket"
version = "0.1.0"
authors = [""]
edition = "2018"

[dependencies]
rocket = "0.4.6"
serde = { version = "1.0", feature = ["derive"]}
serde_json = "1.0"
serde_derive = "1.0"

[dependencies.rocket_contrib]
version = "0.4.6"
default-features = false
features = ["json"]

Content-Type: application/jsonPostman 内でヘッダーを構成しました。リクエストの本文は次の{"status": "running"}とおりです。

ここに画像の説明を入力

私は得ています

Error: Couldn't parse JSON body: Error("EOF while parsing a value", line: 1, column: 0)
4

1 に答える 1