Bundle Lightweight embedded web server. Handles inbound HTTP requests with typed access to method, path, headers, and body; Response supports content-type, compression, redirects, and cookies. Compile with -lib net_server.
Request
Web request
Operations
- GetHeader
- GetLocalAddress
- GetMethod
- GetRemoteAddress
- GetRequestUrl
- ParseMultipartEncoding
- ParseUrlEncoding
- ReadBody
GetHeader #
Gets a HTTP header
method : public : GetHeader(name:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
Return
| Type | Description |
|---|---|
| String | header value |
Example
content_type := request->GetHeader("Content-Type");
if(content_type <> Nil) {
content_type->PrintLine(); # application/json
};GetLocalAddress #
Gets a the local address
method : public : GetLocalAddress() ~ StringReturn
| Type | Description |
|---|---|
| String | local address |
Example
local := request->GetLocalAddress();
local->PrintLine(); # e.g. 0.0.0.0:8080GetMethod #
Gets the request method
method : public : GetMethod() ~ Request->MethodReturn
| Type | Description |
|---|---|
| Request->Method | request method |
Example
# inside a web server handler:
method := request->GetMethod();
if(method = Web.Server.Request->Method->GET) {
response->WriteBody("Hello from GET");
} else if(method = Web.Server.Request->Method->POST) {
body := request->ReadBody();
response->WriteBody(String->New(body));
};GetRemoteAddress #
Gets a the remote address
method : public : GetRemoteAddress() ~ StringReturn
| Type | Description |
|---|---|
| String | remote address |
Example
addr := request->GetRemoteAddress();
addr->PrintLine(); # e.g. 192.168.1.10GetRequestUrl #
Gets a the remote address
method : public : GetRequestUrl() ~ StringReturn
| Type | Description |
|---|---|
| String | remote address |
Example
# log the full request URL in a handler:
url := request->GetRequestUrl();
url->PrintLine(); # e.g. /api/users?page=2ParseMultipartEncoding # native
Parses multipart encoding
function : native : ParseMultipartEncoding(encoded:Byte[]) ~ Vector<ContentType>Parameters
| Name | Type | Description |
|---|---|---|
| encoded | Byte | encoded bytes |
Return
| Type | Description |
|---|---|
| Vector<ContentType> | content parts |
ParseUrlEncoding # function
Parses URL encoding
function : ParseUrlEncoding(encoded:String) ~ Map<String,String>Parameters
| Name | Type | Description |
|---|---|---|
| encoded | String | encoded bytes |
Return
| Type | Description |
|---|---|
| Map<String,String> | name value pairs |
Example
body := String->New(request->ReadBody());
params := Web.Server.Request->ParseUrlEncoding(body);
params->Find("username")->PrintLine(); # e.g. alice
params->Find("password")->PrintLine(); # e.g. secret