Created
May 6, 2015 18:59
-
-
Save phone/32e0a55b2b48d10f6db4 to your computer and use it in GitHub Desktop.
httpd eg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char *argv[]) { | |
httpd_registry_init(); | |
httpd_register("/", "GET", handle_e404); | |
httpd_register("/ping", "GET", handle_ping); | |
httpd_register("/recommend", "GET", handle_recommend); | |
httpd_err_register(HTTP_BAD_REQUEST, handle_e400); | |
httpd_err_register(HTTP_NOT_FOUND, handle_e404); | |
httpd_err_register(HTTP_INTERNAL_SERVER_ERROR, handle_e500); | |
httpd_start(PORT, 2, 10000); | |
} | |
int handle_recommend(Request * req, Response * resp) | |
{ | |
int ret = HTTPD_SUCCESS; | |
const char *rbody = NULL; | |
struct query *qry = NULL; | |
Itemscore *recs = NULL; | |
if ((qry = malloc(sizeof(*qry))) == NULL) { | |
ret = HTTP_INTERNAL_SERVER_ERROR; | |
goto CLEANUP; | |
} | |
if (url_parse(req->url, qry) != 0) { | |
ret = HTTP_NOT_FOUND; | |
goto CLEANUP; | |
} | |
if ((recs = recommend(db, qry->personid, 3)) == NULL) { | |
ret = HTTP_NOT_FOUND; | |
goto CLEANUP; | |
} | |
// ..................... | |
// you get the idea | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment