Function routerify_json_response::json_success_resp [−][src]
pub fn json_success_resp<B, D>(data: &D) -> Result<Response<B>> where
B: HttpBody + From<Vec<u8>> + Send + Sync + Unpin + 'static,
D: Serialize + Send + Sync + Unpin,
Expand description
Generates a success JSON response with the provided data and the OK 200
status code.
It generates JSON response in the following JSON format:
{
"status": "success",
"code": "200",
"data": "<data>"
}
Examples
use hyper::{Body, Request, Response, StatusCode};
use routerify_json_response::{json_success_resp};
async fn list_users_handler(_: Request<Body>) -> Result<Response<Body>, routerify_json_response::Error> {
// Fetch response data from somewhere.
let users = ["Alice", "John"];
// Generate a success JSON response with the data in the following format:
// { "status": "success", code: 200, data: ["Alice", "John"] }
json_success_resp(&users)
}