Struct rocketjson_data::api::response::ApiResponse[][src]

pub struct ApiResponse<T> {
    pub json: Json<T>,
    pub status: Status,
}
Expand description

Is returned by enpoints to achieve a Json Response

Requirements

T has to implement serde::Serialize

Example

  • Code
#[derive(serde::Serialize)]
pub struct TestResponse {
   data: String
}

#[post("/test")]
pub fn test() -> rocketjson::ApiResponse<TestResponse> {
     rocketjson::ApiResponse::new(
         rocket::http::Status::Ok,
         TestResponse { data: String::from("test") }
     )
}
  • Response (200 OK)
{
     data: "test"
}

Fields

json: Json<T>

This is the Json-data sent to the client

status: Status

This is the Statuscode sent to the client, it is not included in the Json

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Converts self into a collection.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more