32 size_t uri_len = strnlen(uri, 1024);
34 mg_printf(conn,
"HTTP/1.1 400 Bad Request\r\nContent-Type: "
35 "text/plain\r\n\r\nMissing username\n");
39 const char *username = uri + 1;
42 mg_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
44 "{\n \"login\": \"%s\",\n \"name\": \"%s\",\n \"company\": "
45 "\"%s\",\n \"location\": \"%s\"\n}\n",
60 char *port_str =
NULL;
61 if (asprintf(&port_str,
"%d", port) == -1) {
62 (void)fprintf(stderr,
"Failed to allocate memory for port\n");
66 const char *options[] = {
"listening_ports",
78 (void)fprintf(stderr,
"Failed to start Civetweb server\n");
84 printf(
"Server started on port %s. Visit http://localhost:%s/USERNAME\n",
86 puts(
"Press Ctrl+C to quit.");
CIVETWEB_API void mg_stop(struct mg_context *ctx)
CIVETWEB_API const struct mg_request_info * mg_get_request_info(const struct mg_connection *conn)
CIVETWEB_API struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
CIVETWEB_API int mg_printf(struct mg_connection *conn, const char *fmt,...)
CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
static int user_handler(struct mg_connection *conn, void *cbdata)
HTTP request handler for user lookup.
void start_http_server(int port)
Starts an HTTP server on the specified port.
Declaration of the HTTP server functions.
Structure representing a GitHub user.
const char * name
Full name.
const char * login
GitHub username.
const char * location
User's location.
const char * company
Company name.
struct mg_callbacks callbacks
User fetch_github_user(const char *username)
Fetch a GitHub user's information via the GitHub API.