add: Response 添加一个json方法,便捷的回复json格式数据;request添加一个context成员,便于在处理链的各个环节共享数据
This commit is contained in:
@@ -43,6 +43,10 @@ namespace MIN {
|
||||
// queryParams
|
||||
MIN_MAP<std::string, std::string> queryParams;
|
||||
|
||||
// 上下文数据
|
||||
// 可以再 preprocessor -> controller -> postprocessor 这条处理链的任意缓解向上下文中存取信息
|
||||
nlohmann::json context;
|
||||
|
||||
void init() {
|
||||
type = MIN_WEB_REQUEST;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,8 @@
|
||||
#include "MINWebResponse.h"
|
||||
|
||||
namespace MIN {
|
||||
void MINWebResponse::json(const nlohmann::json &jsonData) {
|
||||
this->contentType = MINWebServer::APPLICATION_JSON;
|
||||
this->body = jsonData.dump();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,12 @@ namespace MIN {
|
||||
void init() {
|
||||
type = MIN_WEB_RESPONSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回JSON格式的数据
|
||||
* @param jsonData
|
||||
*/
|
||||
void json(const nlohmann::json &jsonData);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ int main () {
|
||||
service.homePage = "index.html";
|
||||
service.baseUrl = "/MIN/Web/test";
|
||||
|
||||
std::cout << getMINHttpMethodEnumFromStr("GET") << std::endl;
|
||||
std::cout << getMINHttpStatusEnumFromStr("Continue") << std::endl;
|
||||
|
||||
service.GET("/getUserInfo", [](std::shared_ptr<MINWebRequest> &request,
|
||||
std::shared_ptr<MINWebResponse> &response) {
|
||||
nlohmann::json result = {
|
||||
|
||||
Reference in New Issue
Block a user