C and C++ web framework.
http://rapida.vilor.one/docs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
#include "../../include/rapida.h" |
|
#include "../../include/servers/fcgi.h" |
|
#include <string.h> /* for strdup() */ |
|
#include <stdio.h> |
|
|
|
|
|
/* |
|
* \brief Process home page request. |
|
* |
|
* \param req Request. |
|
* \param res Response. |
|
* \param userdata Additional data that you can pass to this handler |
|
* when adding a route. |
|
*/ |
|
static void home_page_handler(rpd_req *req, rpd_res *res, void *userdata) |
|
{ |
|
/* Check request method */ |
|
switch (req->method) { |
|
case GET: |
|
/* Process GET request */ |
|
res->status = rpd_res_st_ok; |
|
|
|
/* Please allocate data on the heap, |
|
* because after calling this handler |
|
* Rapida will free it all. |
|
*/ |
|
res->content_type = strdup("text/plain"); |
|
res->body = strdup("Hello World!"); |
|
break; |
|
default: |
|
/* Other request methods are not implemented, |
|
* so set the appropriate response status. |
|
*/ |
|
res->status = rpd_res_st_not_implemented; |
|
break; |
|
} |
|
|
|
/* |
|
* You don't have to do something like send a response. |
|
* Rapida will do this after calling this handler. |
|
*/ |
|
} |
|
|
|
int main() |
|
{ |
|
rpd_app app; |
|
/* Initialize application. */ |
|
rpd_app_create(&app); |
|
|
|
/* Add home "/" page handler. */ |
|
rpd_app_add_route(&app, "/", &home_page_handler, NULL); |
|
|
|
/* Run the application and return its status code. */ |
|
return rpd_fcgi_server_start(&app, "/tmp/webapp.socket"); |
|
}
|
|
|