More docs

This commit is contained in:
Franklin 2022-08-23 09:44:00 -04:00
parent 30ba69d025
commit 5aeb81d7ee
1 changed files with 8 additions and 1 deletions

View File

@ -15,7 +15,7 @@ use crate::dtos::message::MessageResource;
/// if(*number > 0){ /// if(*number > 0){
/// return TypedHttpResponse::return_standard_response(StatusCode::OK, String::from("This is my test response!")); /// return TypedHttpResponse::return_standard_response(StatusCode::OK, String::from("This is my test response!"));
/// } /// }
/// TypedHttpResponse::return_empty_response(StatusCode::BAD_REQUEST); /// TypedHttpResponse::return_empty_response(StatusCode::BAD_REQUEST)
/// } /// }
/// ///
/// ``` /// ```
@ -24,6 +24,13 @@ pub struct TypedHttpResponse<B: Serialize = String> {
} }
impl<B: Serialize> TypedHttpResponse<B> { impl<B: Serialize> TypedHttpResponse<B> {
/// Returns a response with the json struct you define inside + Status code /// Returns a response with the json struct you define inside + Status code
/// ```
/// use actix_web::{http::StatusCode};
/// use actix_web_utils::extensions::typed_response::TypedHttpResponse;
///
/// TypedHttpResponse::return_standard_response(StatusCode::OK, String::from("Anything in here")); //Instead of string you can put anything here as long as it is serializable.
///
/// ```
pub fn return_standard_response(status_code: StatusCode, body: B) -> TypedHttpResponse<B>{ pub fn return_standard_response(status_code: StatusCode, body: B) -> TypedHttpResponse<B>{
TypedHttpResponse { TypedHttpResponse {
response: HttpResponse::with_body(StatusCode::from_u16(u16::from(status_code)).unwrap(), Some(web::Json(Ok(body)))) response: HttpResponse::with_body(StatusCode::from_u16(u16::from(status_code)).unwrap(), Some(web::Json(Ok(body))))