Skip to content

Instantly share code, notes, and snippets.

@rockos
Last active December 18, 2015 08:39
Show Gist options
  • Save rockos/5755567 to your computer and use it in GitHub Desktop.
Save rockos/5755567 to your computer and use it in GitHub Desktop.
/**
* simple RESTful server on SNOWSHOE
*
* @author : rockos
*/
#include "srvhttp.h"
static DBM dbm;
#define HELLO_WORLD "<html><head><title>Do you call me?</title>\
</head><body>Hello world.</body></html>"
/**
* Simple http response
*
*/
int get_reg(const void *cls, struct MHD_Connection* con) {
struct RCS_FH_RES res;
res.form = HELLO_WORLD;
res.form_length = strlen(HELLO_WORLD);
/* processing */
/* response */
rcsfh_response(con, &res);
}
#define REST_TEXT "<html><head><title>this is restful</title>\
</head><body>Do you call REST API.</body></html>"
/**
* REST API must be implemented.
*/
int get_rest(const void *cls, struct MHD_Connection* con) {
struct RCS_FH_RES res;
res.form = REST_TEXT;
res.form_length = strlen(REST_TEXT);
/* processing */
/* response */
rcsfh_response(con, &res);
}
#define PORT 8888
#define redisHOST "127.0.0.1"
#define redisPORT 6379
/**
*
*
*/
int main(void) {
int rc;
DBM dbm;
struct MHD_Daemon *dmn;
struct H_CLS {
DBM *hdb;
int none;
} hcls;
struct RCS_FH_ROUTE_MAP map[] = {
{"/rest/reg", get_reg, &hcls},
{"/rest/api", get_rest, &hcls},
/* {"/rest/state", &get_state, hcls} */
{NULL, NULL, NULL}
};
rc = rcsfr_connect(redisHOST, redisPORT, &dbm);
if (rc == -1) {
return;
}
hcls.hdb = &dbm;
/* start http thread */
dmn = rcsfh_start(PORT, (void *)map);
getchar();
/* disconnect redis server. */
rcsfr_disconnect(&dbm);
/* stop http thread */
rcsfh_stop(dmn);
return ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment