Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(api): Add send_mam_message API
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Wei Wu committed Apr 4, 2019
1 parent f576f6a commit 153727f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions accelerator/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ int main(int, char const**) {
res << json_result;
});

mux.handle("/mam")
.method(served::method::OPTIONS,
[&](served::response& res, const served::request& req) {
set_method_header(res, HTTP_METHOD_OPTIONS);
})
.post([&](served::response& res, const served::request& req) {
status_t ret = SC_OK;
char* json_result;
char* chid_result;

if (req.header("content-type").find("application/json") ==
std::string::npos) {
cJSON* json_obj = cJSON_CreateObject();
cJSON_AddStringToObject(json_obj, "message",
"Invalid request header");
json_result = cJSON_PrintUnformatted(json_obj);

res.set_status(SC_HTTP_BAD_REQUEST);
cJSON_Delete(json_obj);
} else {
api_mam_send_message(&ta_core.tangle, &ta_core.service,
req.body().c_str(), &json_result, &chid_result);
ret = set_response_content(ret, &json_result);
res.set_status(ret);
}

set_method_header(res, HTTP_METHOD_POST);
res << json_result;
});

/**
* @method {get} /tag/:tag Find transactions by tag
*
Expand Down

0 comments on commit 153727f

Please sign in to comment.