Skip to content

Http

Spice
import "std/net/http";

HttpServer struct

Struct, representing a simple HTTP server

Constructors

ctor

Spice
public p HttpServer.ctor(unsigned short port = HTTP_PORT_DEFAULT)

Used to initialize a HTTP server instance, listening on a specific port for incoming requests

Parameters

Name Type Description
port unsigned short (default: HTTP_PORT_DEFAULT)

Methods

start

Spice
public f<bool> HttpServer.start()

Returns: bool

serve

Spice
public f<bool> HttpServer.serve(string path, string htmlContent)

Register a route on the server that responds with the given HTML content

Parameters

Name Type Description
path string Request path to serve
htmlContent string HTML content to respond with

Returns: bool — true if the route was registered successfully, false otherwise