v / examples / fasthttp / README.md
71 lines · 47 sloc · 1.31 KB · 645e94ea994bc2e5d689092ae5aa65eb99d4511d
Raw

Fasthttp Example

A simple HTTP server example using the fasthttp module from vlib/fasthttp.

Features

Building

./v examples/fasthttp

Running

./examples/fasthttp/fasthttp

The server will listen on http://localhost:3000

Testing

Home endpoint

curl http://localhost:3000/

Get user by ID

curl http://localhost:3000/user/123

Create user

curl -X POST http://localhost:3000/user

404 response

curl http://localhost:3000/notfound

File Structure

Architecture

The example demonstrates:

  1. Request Routing: The handle_request() function routes incoming HTTP requests based on method and path
  2. Response Handling: Controllers return HTTP responses with proper headers and status codes
  3. Content Type: All responses are returned as []u8 (byte arrays)The fasthttp module handles: