Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve README with Build Instructions and Snippet Fixes. #4

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <th.h>
#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");
Expand All @@ -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.
Expand Down Expand Up @@ -75,7 +83,7 @@ Example - Path capturing:
#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)
{
const char* msg = th_get_path_param(req, "msg");
th_body_printf(res, "Hello, %s!", msg);
Expand All @@ -101,15 +109,15 @@ Example - File serving:
#include <th.h>

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);
return TH_ERR_OK;
}

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;
Expand Down
Loading