memgraph/speedy/response.hpp

36 lines
788 B
C++
Raw Normal View History

#pragma once
2015-10-09 07:24:12 +08:00
#include "request.hpp"
#include "http/response.hpp"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
2015-10-09 07:24:12 +08:00
namespace sp
{
class Response : public http::Response<Request, Response>
{
public:
using http::Response<Request, Response>::Response;
2015-10-18 16:01:53 +08:00
void json(http::Status code, const rapidjson::Document& document)
{
rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
document.Accept(writer);
// TODO: error handling
2015-10-18 16:01:53 +08:00
this->send(code, strbuf.GetString());
}
void json(const rapidjson::Document& document)
{
2015-10-18 16:01:53 +08:00
this->json(http::Status::Ok, document);
}
2015-10-09 07:24:12 +08:00
};
using request_cb_t = std::function<void(Request&, Response&)>;
}