Getting Started with Netiqo
Create your first self-hosted web server in minutes. Netiqo is a lightweight, high-performance framework for building HTTP servers easily and efficiently.
Program.cs
using Netiqo.Framework;
var host = new Host("127.0.0.1", 8080);
host.LogMessage += Console.WriteLine;
host.RegisterRoute(new Route("/", Request.HttpMethod.GET,
htmlResponse: "<h1>Homepage</h1>"));
await host.StartAsync();
This code creates a Web server listening on port 8080 with a basic route that responds with a simple HTML page.
Project Structure
Files in the wwwroot/ folder are automatically served by the server, allowing you to distribute CSS, JavaScript, images, and other assets needed for your application.
Host Class
Main class for web server management with optional support for HTTPS.
Host Constructor
public Host(string ip, int port,
string certPath = null,
string certPassword = null)
Parameters
- ip: IP address on which to listen (e.g. "127.0.0.1")
- port: Port on which to start the server
- certPath: Path to PFX certificate (optional for HTTPS)
- certPassword: Password for the certificate (optional)
Easily configure secure connections using PFX certificates for production environments.
Route Class
Route definition with support for dynamic handlers or static HTML responses.
Route Constructor
public Route(string path, Request.HttpMethod method,
Func<string, Task<string>> handler = null,
string htmlResponse = null)
Parameters
- path: Route path (e.g. "/api/users")
- method: Method HTTP (GET, POST, PUT, ecc.)
- handler: Function to handle the request
- htmlResponse: Static HTML response
You can use a static HTML response.
Route Attribute
Define your routes directly on the methods of the controller classes with attributes.
Example of Route Attribute
// Definition of a controller
public class TestController
{
[Route("/api/test", Request.HttpMethod.GET)]
public string Test(string body) => "<h1>Test</h1>";
}
// Controller registration
host.RegisterRoutesFromAttributes(new TestController());
Route attributes allow the code to be organized in a more structured way, separating routing logic from server configuration.
HTTP Methods Support
Full support for all standard HTTP methods.
Supported Methods
Retrieve a representation of the resource
Send an entity to a resource
Replaces all representations of the resource
Deletes the specified resource
Applies partial changes to a resource
Retrieves the metadata of the resource
Runs a loopback test
Describes the communication options
Establishes a tunnel to the server
Device Class
Utility to obtain network information and default configurations.
Examples of Use
// Get the local IPv4 address
string ip = Device.Ipv4();
// Get the default port (8080)
int defaultPort = Device.DefaultPort;
// Configure the server with default values
var host = new Host(Device.Ipv4(), Device.DefaultPort);
The Device class runs on all platforms supported by .NET, providing consistent information.
Static HTML Routes
Perfect for informational pages or content that does not change frequently.
Example of Static Route
host.RegisterRoute(new Route("/about", Request.HttpMethod.GET,
htmlResponse: "<h1>About Us</h1><p>About our company</p>"));
Static routes are served directly from memory, offering extremely fast response times.
Dynamic Handlers
For content that requires server-side processing and interaction with data.
Example of Dynamic Handler
host.RegisterRoute(new Route("/login", Request.HttpMethod.POST, async body =>
{
var parsed = HttpUtility.ParseQueryString(body);
return $"<h1>Welcome {parsed["username"]}</h1>";
}));
Dynamic handlers allow you to create complex logic, integrate databases, and interact with external services.
Configuration from JSON
Load routes from external JSON files for more flexible management.
routes.json
Uploading to Server
// Load routes from a JSON file
host.LoadRoutesFromJson("config/routes.json");
Remote Library Loading
Load and use external libraries dynamically in your Netiqo applications.
Loading Remote Libraries
Library library = new Library();
library.LogHandler += (message) =>
{
Console.WriteLine($"{message}");
};
library.LibraryLoadCompleted += (success) =>
{
if (success)
{
// Test call from function loaded from external library
Get.PrintMessage("Library loaded successfully!");
}
else
{
Console.WriteLine("Failed to load library.");
}
};
// Load a library from URL with optional hash verification
library.LoadLibraryFromWeb("https://yourdownloadlink", "a1b2c3...");
public void LoadLibraryFromWeb(string url, string? hash = null)
Loads managed and unmanaged libraries from remote URL with optional SHA256 hash verification.
SHA256 Verification
Built-in verification of SHA256 hashes for data downloaded via URL.
Advanced Security
// Upload a library with SHA256 verification
library.LoadLibraryFromWeb(
"https://yourdownloadlink",
"a1b2c3..."
);
SHA256 verification ensures the integrity of downloaded files and prevents the execution of manipulated or corrupted code.
In-Memory Execution
Libraries are loaded and executed directly in memory, increasing security and performance.
Main Features
Discover all the powerful features offered by Netiqo Framework.
Main Features
Lightweight & Performing
Lightweight and high-performance HTTP TCP server.
Declarative Routing
Route definition via attributes or JSON/XML configurations.
Full HTTP Support
Support for all standard HTTP methods (GET, POST, PUT, etc.).
SSL Support
SSL support with X.509 certificates.
File Management
Automatic chunk response and simplified file management.
IP detection
Cross-platform detection of IPv4 addresses.
Deployment Scenarios
Netiqo is versatile and suitable for all kinds of applications.
Usage Scenarios
Embedded Applications
Integrate web servers directly into your desktop or IoT applications
Local Backend
Create APIs and services accessible from the local network without complex configurations
Microservices
Develops lightweight microservices for distributed architectures
New Features in 1.3.0
Learn about the powerful new features introduced in Netiqo Framework version 1.3.0.
What's new
Remote Library Upload
Remote library upload system (managed and unmanaged) via URL.
In-Memory Execution
In-memory loading and execution of libraries for greater flexibility.
Extended Framework
Support for more general use cases beyond web servers.
SHA256 verification
Built-in verification of SHA256 hashes for data downloaded via URL.