|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
Advanced server example with route groups, WebSocket, and auth middleware. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "csilk/csilk.h"
Data Structures | |
| struct | user_t |
| Example user model struct. More... | |
Functions | |
| void | auth_required (csilk_ctx_t *c) |
| Custom auth middleware — validates Authorization header. | |
| void | get_user_handler (csilk_ctx_t *c) |
| Handler for GET /api/v1/users/:id — returns a mock user. | |
| void | post_data_handler (csilk_ctx_t *c) |
| Handler for POST /api/v1/data — echoes received JSON with a 50ms delay. | |
| void | ws_on_message (csilk_ctx_t *c, const uint8_t *payload, size_t len, int opcode) |
| WebSocket message callback — echoes received messages back to client. | |
| void | ws_handler (csilk_ctx_t *c) |
| WebSocket upgrade handler — performs handshake and sets message callback. | |
| void | ping_handler (csilk_ctx_t *c) |
| Simple ping handler — returns "pong". | |
| void | static_handler (csilk_ctx_t *c) |
| Static file handler — serves files from the ./public directory. | |
| int | main () |
Advanced server example with route groups, WebSocket, and auth middleware.
| struct user_t |
| void auth_required | ( | csilk_ctx_t * | c | ) |
Custom auth middleware — validates Authorization header.
| void get_user_handler | ( | csilk_ctx_t * | c | ) |
Handler for GET /api/v1/users/:id — returns a mock user.
| int main | ( | void | ) |
| void ping_handler | ( | csilk_ctx_t * | c | ) |
Simple ping handler — returns "pong".
| void post_data_handler | ( | csilk_ctx_t * | c | ) |
Handler for POST /api/v1/data — echoes received JSON with a 50ms delay.
| void static_handler | ( | csilk_ctx_t * | c | ) |
Static file handler — serves files from the ./public directory.
| void ws_handler | ( | csilk_ctx_t * | c | ) |
WebSocket upgrade handler — performs handshake and sets message callback.
| void ws_on_message | ( | csilk_ctx_t * | c, |
| const uint8_t * | payload, | ||
| size_t | len, | ||
| int | opcode | ||
| ) |
WebSocket message callback — echoes received messages back to client.