Returning multiple statuses
When it comes to creating a user, we merely return a created status code or a conflict status code and nothing else. We do not need to return data because the person who has just created the user already knows the user details. In Rocket, we can return multiple different status codes with no body. We can explore this concept in the src/views/to_do/create.rs
file, but first, we must ensure that we import the following:
use crate::diesel; use diesel::prelude::*; use rocket::serde::json::Json; use rocket::http::Status; use crate::database::DB; use crate::json_serialization::new_user::NewUserSchema; use crate::models::user::new_user::NewUser; use crate::schema::users;
Now that we have everything we need, we can define the outline of the view with the following code:
#[post("/create", data = "<new_user>", format = "json")] pub async fn create_user(new_user: Json<NewUserSchema>, db: DB) ...