add: generic response makers
This commit is contained in:
parent
2d992cfe3c
commit
6178ef3c7b
13 changed files with 200 additions and 503 deletions
endpoints
|
@ -23,26 +23,7 @@ api_v1_relays_GET(struct http_message *hm, endpoint_args_t *args, endpoint_respo
|
|||
cJSON_AddItemToArray(json, json_relay);
|
||||
}
|
||||
|
||||
char *json_str = cJSON_Print(json);
|
||||
if (json_str == NULL)
|
||||
{
|
||||
LOG_ERROR("failed to print relays json\n");
|
||||
|
||||
static const char content[] = "failed to print json for relays";
|
||||
response->status_code = 500;
|
||||
response->content_type = "text/plain";
|
||||
response->content_length = STRLEN(content);;
|
||||
response->content = content;
|
||||
response->alloced_content = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
response->status_code = 200;
|
||||
response->content_type = "application/json";
|
||||
response->content_length = strlen(json_str);
|
||||
response->content = json_str;
|
||||
response->alloced_content = true;
|
||||
}
|
||||
endpoint_response_json(response, 200, json);
|
||||
cJSON_Delete(json);
|
||||
relay_free_list(all_relays);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue