Skip to content

fasthttp #

fn new_server #

fn new_server(port int, handler fn (req HttpRequest) ![]u8) !&Server

new_server creates and initializes a new Server instance.

struct HttpRequest #

struct HttpRequest {
pub mut:
	buffer         []u8 // A V slice of the read buffer for convenience
	method         Slice
	path           Slice
	version        Slice
	client_conn_fd int
}

HttpRequest represents a parsed HTTP request. The slices point to memory within the connection's buffer and are only valid for the duration of the request.

struct Server #

struct Server {
pub mut:
	port            int
	socket_fd       int
	kq              int
	request_handler fn (req HttpRequest) ![]u8 = unsafe { nil }
	worker_data     WorkerData
	threads         [num_threads]C.pthread_t
}

Server holds the entire state of the web server instance.

fn (Server) run #

fn (mut s Server) run() !

const C.AF_INET u8 // run starts the server and enters the main event loop.

struct Slice #

struct Slice {
pub mut:
	buf &u8 = unsafe { nil }
	len int
}

Slice represents a part of a larger buffer, without owning the memory. It's useful for representing parts of the request buffer like the method and path.

fn (Slice) str #

fn (s Slice) str() string

str returns the V string representation of the slice.