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 API send trytes for HTTP endpoint
Browse files Browse the repository at this point in the history
Connect api_send_trytes to served framework after implementation of it
is complete. As of mocrihttpd, it should have another issue for this.
  • Loading branch information
Yu Wei Wu committed May 28, 2019
1 parent d514202 commit abb820e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions accelerator/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,40 @@ int main(int argc, char* argv[]) {
res << json_result;
});

/**
* @method {post} /tryte send trytes
*
* @return {String} transaction object
*/
mux.handle("/tryte")
.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;

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 {
ret = api_send_trytes(&ta_core.tangle, &ta_core.service,
req.body().c_str(), &json_result);
ret = set_response_content(ret, &json_result);
res.set_status(ret);
}

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

/**
* @method {get} {*} Client bad request
* @method {options} {*} Get server information
Expand Down

0 comments on commit abb820e

Please sign in to comment.