Fix Makefiles and add README
The http/ and hashtable/ Makefiles named sources that do not exist (test.c, net.c, net.h in http/; http.h in hashtable/) and had no way to find the sibling hashtable/llist sources they link against, so neither directory built at all. Both now compile those sources with explicit recipes. VPATH would be the terser fix but is deliberately avoided: it searches for targets as well as sources, so a stale ../llist/test.o gets linked in place of a freshly compiled one, and hashtable/test silently runs the linked-list suite instead of its own. llist/Makefile built fine; its .PHONY read "all," with a comma, making that the literal target name, and test.o was missing its llist.h dependency. README covers layout, build, run, the use()/Handler routing API, and the library tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
9904bd2212
commit
1b54b78416
4 changed files with 108 additions and 28 deletions
72
README.md
72
README.md
|
|
@ -1 +1,71 @@
|
|||
Addon Libraries to C Programming Language
|
||||
# pico-http
|
||||
|
||||
A minimal HTTP server in C, with the hashtable and linked-list libraries it is built on.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
http/ server and routing framework
|
||||
hashtable/ route table
|
||||
llist/ bucket chaining for the hashtable
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Needs `gcc` and `make`.
|
||||
|
||||
```sh
|
||||
cd http && make
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```sh
|
||||
./pico-http
|
||||
```
|
||||
|
||||
Listens on port 3000, set by `PORT` in `http/http.h`.
|
||||
|
||||
```sh
|
||||
$ curl localhost:3000/login
|
||||
Login works!
|
||||
|
||||
$ curl localhost:3000/signup
|
||||
Sign Up works!
|
||||
```
|
||||
|
||||
Unregistered paths return `400 Bad request`.
|
||||
|
||||
## Adding a route
|
||||
|
||||
A handler fills in `Res`:
|
||||
|
||||
```c
|
||||
void hello(Req* req, Res* res)
|
||||
{
|
||||
char* content = "Hello\n";
|
||||
|
||||
res->status = 200;
|
||||
res->content_type = "text/html";
|
||||
res->content_length = strlen(content);
|
||||
res->body = content;
|
||||
}
|
||||
```
|
||||
|
||||
Register it before starting the server, in `main.c`:
|
||||
|
||||
```c
|
||||
use("/hello", &hello);
|
||||
http_start(PORT);
|
||||
```
|
||||
|
||||
Paths match exactly — `/hello` will not match `/hello/`.
|
||||
|
||||
## Library tests
|
||||
|
||||
```sh
|
||||
cd llist && make && ./test
|
||||
cd hashtable && make && ./test
|
||||
```
|
||||
|
||||
`make clean` in any of the three directories removes its objects and binary.
|
||||
|
|
|
|||
Loading…
Reference in a new issue