Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
JsonResponse.h
Go to the documentation of this file.
1
11 #pragma once
12
13#include <string>
14#include <nlohmann/json.hpp>
15
16class HttpResponse;
17
18namespace JsonResponse {
19
20// Send helpers
21void sendSuccess(HttpResponse& res, const nlohmann::json& data = {}, const std::string& message = "");
22void sendCreated(HttpResponse& res, const nlohmann::json& data = {}, const std::string& message = "");
23void sendMessage(HttpResponse& res, const std::string& message);
25void sendJson(HttpResponse& res, const nlohmann::json& raw, int statusCode = 200);
26
27// Error helpers
28void sendError(HttpResponse& res, int statusCode, const std::string& code, const std::string& message);
29inline void sendNotFound(HttpResponse& res, const std::string& message) {
30 sendError(res, 404, "not_found", message);
31}
32inline void sendBadRequest(HttpResponse& res, const std::string& message) {
33 sendError(res, 400, "bad_request", message);
34}
35inline void sendUnauthorized(HttpResponse& res, const std::string& message) {
36 sendError(res, 401, "unauthorized", message);
37}
38
39} // namespace JsonResponse
Represents an HTTP response object.
void sendNotFound(HttpResponse &res, const std::string &message)
void sendMessage(HttpResponse &res, const std::string &message)
void sendBadRequest(HttpResponse &res, const std::string &message)
void sendUnauthorized(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)