https://github.com/boudra/griffin
A simple HTTP server library for C
https://github.com/boudra/griffin
c http http-server simple
Last synced: 5 months ago
JSON representation
A simple HTTP server library for C
- Host: GitHub
- URL: https://github.com/boudra/griffin
- Owner: boudra
- License: apache-2.0
- Created: 2016-06-06T10:01:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-09-20T13:45:30.000Z (over 5 years ago)
- Last Synced: 2025-01-04T17:12:36.840Z (about 1 year ago)
- Topics: c, http, http-server, simple
- Language: C
- Homepage:
- Size: 39.1 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Griffin
Tiny HTTP server library in C, inspired by the design of [Plug](https://github.com/elixir-plug/plug);
I built this for fun and to learn the HTTP protocol and sockets in more depth, it has not been tested in production.
## Tasks
- [x] Basic HTTP server
- [x] Basic routing and path parameter parsing
- [ ] HTTPS/TLS
## Example
```c
#include
#include
#include
void root(gn_conn_t* conn, gn_map_t* params) {
gn_put_body(conn, "Root");
gn_put_status(conn, 200);
}
void say_hello(gn_conn_t* conn, gn_map_t* params) {
const char* name = gn_map_get(params, "name");
gn_put_body(conn, name);
gn_put_status(conn, 200);
}
int main(int argc, char *argv[]) {
gn_endpoint_t endpoint = {0};
gn_router_t router = {0};
gn_add_middleware(&endpoint, &gn_router, &router);
gn_router_match(&router, GET, "/", root);
gn_router_match(&router, GET, "/hello/:name", say_hello);
gn_start_server(&endpoint, "0.0.0.0", 8080);
return 0;
}
```