From d78300914621acb3043b6b1115345c7497389867 Mon Sep 17 00:00:00 2001 From: Raphael Schlarb Date: Thu, 26 Sep 2024 18:41:26 +0200 Subject: [PATCH] Improve README with Build Instructions and Snippet Fixes. - Add brief guide on how to build the example snippet. - Update `th_request` pointers be `const`. --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7618975..f87014b 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ It is not designed to be a full-fledged web server, but rather a simple tool to Hello, World! example: ```c -#include +#include "th.h" static th_err -handler(void* userp, th_request* req, th_response* res) +handler(void* userp, const th_request* req, th_response* res) { th_set_body(res, "Hello, World!"); th_add_header(res, "Content-Type", "text/plain"); @@ -25,6 +25,14 @@ int main() } } ``` +Simply copy the code above to a file (e.g. `hello.c`) where you have the `th.h` and `th.c` files, and compile it with: +```sh +$ gcc -o hello hello.c th.c +``` +Then run the server with: +```sh +$ ./hello +``` I wrote this library because I wanted a simple drop-in solution for the legacy C and C++ codebases I work with, hence the lack of dependencies and new language features. It lacks lots of important features and is not production-ready, but I'll be adding more features and fixing bugs if I have the time. @@ -75,7 +83,7 @@ Example - Path capturing: #include static th_err -handler(void* userp, th_request* req, th_response* res) +handler(void* userp, const th_request* req, th_response* res) { const char* msg = th_get_path_param(req, "msg"); th_body_printf(res, "Hello, %s!", msg); @@ -101,7 +109,7 @@ Example - File serving: #include static th_err -handle_path(void* userp, th_request* req, th_response* res) +handle_path(void* userp, const th_request* req, th_response* res) { const char* path = th_get_path_param(req, "path"); th_body_from_file(res, "root", path); @@ -109,7 +117,7 @@ handle_path(void* userp, th_request* req, th_response* res) } static th_err -handle_index(void* userp, th_request* req, th_response* res) +handle_index(void* userp, const th_request* req, th_response* res) { th_body_from_file(res, "root", "index.html"); return TH_ERR_OK;