Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
JsonRequestHelper.h
Go to the documentation of this file.
1
11 #pragma once
12
13 #include <string>
14 #include <nlohmann/json.hpp>
15
16 using json = nlohmann::json;
17
18 class HttpRequest;
19
24 {
25 public:
32 static json getJsonValue(const HttpRequest& req, const std::string& path);
33
40 static bool hasField(const HttpRequest& req, const std::string& key);
41
48 static std::string getString(const HttpRequest& req, const std::string& key);
49
57 static int getInt(const HttpRequest& req, const std::string& key, int def = 0);
58
66 static double getDouble(const HttpRequest& req, const std::string& key, double def = 0.0);
67
75 static bool getBool(const HttpRequest& req, const std::string& key, bool def = false);
76
82 static json getFullJson(const HttpRequest& req);
83
90 static json getArray(const HttpRequest& req, const std::string& key);
91
98 static json getObject(const HttpRequest& req, const std::string& key);
99
100 private:
106 static json parseJsonBody(const HttpRequest& req);
107 };
108
110#define JSON JsonRequestHelper
111
nlohmann::json json
nlohmann::json json
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
Utility class for working with JSON content in HTTP requests.
static std::string getString(const HttpRequest &req, const std::string &key)
Get a string value from the request body.
static bool getBool(const HttpRequest &req, const std::string &key, bool def=false)
Get a boolean value from the request body.
static json getJsonValue(const HttpRequest &req, const std::string &path)
Extract a nested JSON value using a dot-separated path (e.g., "user.name").
static json parseJsonBody(const HttpRequest &req)
Parse the raw body into a JSON object.
static int getInt(const HttpRequest &req, const std::string &key, int def=0)
Get an integer value from the request body.
static json getArray(const HttpRequest &req, const std::string &key)
Get a JSON array from the request body.
static bool hasField(const HttpRequest &req, const std::string &key)
Check if a JSON field exists.
static json getFullJson(const HttpRequest &req)
Parse and return the full JSON body from the request.
static double getDouble(const HttpRequest &req, const std::string &key, double def=0.0)
Get a double value from the request body.
static json getObject(const HttpRequest &req, const std::string &key)
Get a JSON object from the request body.