Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
JsonView.cpp
Go to the documentation of this file.
1
6// void App::handleStatus(HttpRequest& req, HttpResponse& res) {
7// auto json = model.toJson();
8// JsonView view(json);
9// res.send(view); // or res.send(view, {}); if you prefer consistency
10// }
11
12#include "framework/JsonView.h"
13
14JsonView::JsonView(const nlohmann::json &payload)
15 : payload_(payload) {}
16
17std::string JsonView::render(const std::map<std::string, std::string> &) const
18{
19 return payload_.dump(2); // pretty-print
20}
21
22std::string JsonView::getContentType() const
23{
24 return "application/json";
25}
View for rendering JSON using nlohmann::json, with automatic content type.
JsonView(const nlohmann::json &payload)
Definition JsonView.cpp:14
nlohmann::json payload_
Definition JsonView.h:28
std::string getContentType() const override
Return the MIME content type for this view.
Definition JsonView.cpp:22
std::string render(const std::map< std::string, std::string > &context={}) const override
Render the view body.
Definition JsonView.cpp:17