add: endpoint responses
This commit is contained in:
parent
5a19e99627
commit
5e64f5963c
18 changed files with 587 additions and 235 deletions
endpoints
|
@ -1,4 +1,5 @@
|
|||
#include <cJSON.h>
|
||||
#include <macros.h>
|
||||
#include <constants.h>
|
||||
#include <endpoints/api_v1_relays.h>
|
||||
#include <logger.h>
|
||||
|
@ -7,7 +8,7 @@
|
|||
#include <models/tag.h>
|
||||
|
||||
void
|
||||
api_v1_relays_GET(struct mg_connection *c, endpoint_args_t *args, struct http_message *hm)
|
||||
api_v1_relays_GET(struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response)
|
||||
{
|
||||
(void)args;
|
||||
(void)hm;
|
||||
|
@ -26,14 +27,21 @@ api_v1_relays_GET(struct mg_connection *c, endpoint_args_t *args, struct http_me
|
|||
if (json_str == NULL)
|
||||
{
|
||||
LOG_ERROR("failed to print relays json\n");
|
||||
mg_send_head(c, 500, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "[]");
|
||||
|
||||
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
|
||||
{
|
||||
mg_send_head(c, 200, strlen(json_str), "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "%s", json_str);
|
||||
free(json_str);
|
||||
response->status_code = 200;
|
||||
response->content_type = "application/json";
|
||||
response->content_length = strlen(json_str);
|
||||
response->content = json_str;
|
||||
response->alloced_content = true;
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
relay_free_list(all_relays);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue