A simple HTTP server example using the fasthttp module from vlib/fasthttp.
- Handles GET and POST requests
- Routes requests to different controllers based on HTTP method and path
- Returns appropriate HTTP responses with status codes and content
./v examples/fasthttp./examples/fasthttp/fasthttpThe server will listen on http://localhost:3000
curl http://localhost:3000/curl http://localhost:3000/user/123curl -X POST http://localhost:3000/usercurl http://localhost:3000/notfoundmain.c.v- Entry point and request routercontrollers.v- Request handlers for different routesv.mod- Module metadata
The example demonstrates:
- Request Routing: The
handle_request()function routes incoming HTTP requests based on method and path - Response Handling: Controllers return HTTP responses with proper headers and status codes
- Content Type: All responses are returned as
[]u8(byte arrays)
The fasthttp module handles:
- Low-level socket management
- Request parsing
- Connection handling
- Non-blocking I/O with epoll (Linux) or kqueue (macOS)