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.v- Entry point and request routercontrollers.v- Request handlers for different routesv.mod- Module metadata
The example demonstrates:
- Request Routing: the
handle()append handler routes incoming HTTP requests based on method and path - Response Handling: controllers append the raw HTTP response (headers + body) into the
connection's reused
outbuffer and the handler returns.done - Zero-copy: no per-request response object is allocated; responses go straight into the server's reused, pipelining-batched write buffer
The fasthttp module handles:
- Low-level socket management
- Request parsing
- Connection handling
- Non-blocking I/O with epoll (Linux) or kqueue (macOS)