24 nlohmann::json j = { {
"success",
true} };
25 if (!data.is_null() && !data.empty()) j[
"data"] = data;
26 if (!message.empty()) j[
"message"] = message;
31 nlohmann::json j = { {
"success",
true} };
32 if (!data.is_null() && !data.empty()) j[
"data"] = data;
33 if (!message.empty()) j[
"message"] = message;
HTTP HttpResponse class for managing status, headers, body, and streaming support.
Utility functions to send standard JSON responses using nlohmann::json.
Represents an HTTP response object.
HttpResponse & sendCreated(const nlohmann::json &data={}, const std::string &message="")
HttpResponse & json(const std::string &jsonString)
Send a JSON string/object with correct content type.
void send(const std::string &body)
Send a full response including headers and body.
HttpResponse & status(int code)
Set the HTTP status code.
HttpResponse & sendMessage(const std::string &message)
HttpResponse & sendNoContent()
HttpResponse & sendSuccess(const nlohmann::json &data={}, const std::string &message="")
HttpResponse & sendError(int statusCode, const std::string &code, const std::string &message)
void sendMessage(HttpResponse &res, const std::string &message)
void sendError(HttpResponse &res, int statusCode, const std::string &code, const std::string &message)
void sendNoContent(HttpResponse &res)
void sendSuccess(HttpResponse &res, const nlohmann::json &data, const std::string &message)
void sendJson(HttpResponse &res, const nlohmann::json &raw, int statusCode)
void sendCreated(HttpResponse &res, const nlohmann::json &data, const std::string &message)