Method post in actix-web

⚓ Rust    📅 2026-07-03    👤 surdeus    👁️ 1      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Method post in actix-web

Hello everyone,
I’m using the Actix-Web framework to create an API. I need a POST method that receives data via the request body, and this data needs to conform to a predefined structure. My question is: how do I retrieve the data from the request body? I’ve attached the method and the structure.
Many thanks

structure

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Post {
    pub post_id: i64,
    pub title: String,
    pub content: String,
    pub publication_data: DateTime<Utc>,
}

Method

use actix_web::{post, web};

use crate::domain::post::Post;

#[post("/creation")]
async fn creation_post(post: web::Json<Post>) -> String {
    post.title.to_owned()
}

3 posts - 2 participants

Read full topic

🏷️ Rust_feed