Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
FrameworkView.h
Go to the documentation of this file.
1
13 #pragma once
14 #include <string>
15 #include <map>
16 #include <nlohmann/json.hpp>
17
18 // Forward declaration
19 class HttpResponse;
20
22 public:
23 virtual ~FrameworkView() = default;
24
28 virtual std::string render(const std::map<std::string, std::string>& context = {}) const = 0;
29
33 virtual std::string getContentType() const = 0;
34
38 virtual void applyHeaders(HttpResponse& response) const {}
39
43 virtual std::string render(const nlohmann::json& context) const {
44 return render(); // fallback ignores json
45 }
46 };
47
virtual std::string render(const std::map< std::string, std::string > &context={}) const =0
Render the view body.
virtual std::string getContentType() const =0
Return the MIME content type for this view.
virtual ~FrameworkView()=default
virtual std::string render(const nlohmann::json &context) const
Optional JSON context hook (used by JsonView or convenience).
virtual void applyHeaders(HttpResponse &response) const
Optional hook to set response headers (e.g., Content-Disposition).
Represents an HTTP response object.