To generate HTML from a file, the cweb_send_var_html function may be used:
#include "CWebStudioOne.c"
CwebNamespace cweb;
struct CwebHttpResponse *main_sever(struct CwebHttpRequest *request ){
const char *html = "<html><body><h1>Hello World</h1></body></html>";
return cweb.response.send_var_html(html,200);
}
int main(int argc, char *argv[]){
cweb = newCwebNamespace();
CwebServer server = newCwebSever(5000, main_sever);
cweb.server.start(&server);
return 0;
}
As is done with returning plain text, memory will be automatically cleaned with cweb_send_var_html_cleaning_memory:
#include "CWebStudioOne.c"
CwebNamespace cweb;
struct CwebHttpResponse *main_sever(struct CwebHttpRequest *request ){
char *html = (char*)malloc(1000);
strcat(html, "<html><body><h1>Hello World</h1></body></html>");
return cweb.response.send_var_html_cleaning_memory(html,200);
}
int main(int argc, char *argv[]){
cweb = newCwebNamespace();
CwebServer server = newCwebSever(5000, main_sever);
cweb.server.start(&server);
return 0;
}
These examples show how to return HTML responses.