Skip to content

thebitbrine/QuickMan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuickMan.Lib

Quick way to build self-hosted APIs.

What it does

QuickMan.Lib wraps the .NET HttpListener into a simple API for building lightweight HTTP servers. Define your endpoints as methods, map them to URLs, and you have a working API server in minutes.

No web frameworks, no configuration files, no deployment complexity. Just code your endpoints and start the server.

Production performance

This library has been deployed in production environments handling 20,000+ requests per second on a quad-core i5 processor. The lightweight architecture and efficient threading model deliver enterprise-grade throughput with minimal overhead.

The simplicity doesn't compromise performance - it enables it.

Why this approach works

Traditional web frameworks add layers of abstraction, middleware, and features you might not need. QuickMan strips this down to the essentials:

  • Direct HttpListener access with minimal wrapping
  • Semaphore-based connection limiting prevents resource exhaustion
  • Background thread processing keeps the main thread responsive
  • Zero framework overhead - just your code and the HTTP transport

This results in predictable performance characteristics and resource usage.

Use cases

Perfect for high-performance scenarios where you need HTTP functionality without framework complexity:

  • High-throughput APIs serving thousands of requests per second
  • Microservices requiring minimal resource footprint
  • System utilities that need HTTP interfaces
  • Real-time data endpoints with low latency requirements
  • Development tools and testing infrastructure
  • Inter-service communication in distributed systems

Usage example

private QuickMan API;

public void Run()
{
    API = new QuickMan();
    var endpoints = new Dictionary<string, Action<HttpListenerContext>>();
    
    // Map endpoint names to methods (no leading slash)
    endpoints.Add("status", GetStatus);
    endpoints.Add("data", GetData);
    endpoints.Add("upload", HandleUpload);
    
    // Start server - returns the full URL
    string serverUrl = API.Start(endpoints, 100); // max 100 concurrent connections
    Console.WriteLine($"Server running at {serverUrl}");
}

// http://localhost:1999/status
public void GetStatus(HttpListenerContext context)
{
    API.Respond("Server is running!", context);
}

// http://localhost:1999/data  
public void GetData(HttpListenerContext context)
{
    string jsonData = "{ \"message\": \"Hello World\" }";
    API.Respond(jsonData, "application/json", context);
}

Server startup options

// Default: localhost:1999
API.Start(endpoints);

// Custom port
API.Start(8080, endpoints);

// Custom IP and port  
API.Start(IPAddress.Parse("192.168.1.100"), 8080, endpoints);

// All methods support max connection limit
API.Start(endpoints, 200); // Allow 200 concurrent connections for high throughput

Performance characteristics

  • Concurrent connections: Configurable limit with semaphore-based throttling
  • Request processing: Each request handled on separate background thread
  • Memory efficiency: Minimal allocations and object pooling where possible
  • Throughput scaling: Linear scaling with available CPU cores
  • Low latency: Direct code path from HTTP request to response

Tested production deployments have achieved:

  • 20,000+ requests/second on quad-core i5
  • Sub-millisecond response times for simple endpoints
  • Stable memory usage under sustained load
  • 99.9%+ uptime in production environments

Response helpers

// Simple text/JSON response
API.Respond("Hello World!", context);

// Custom content type
API.Respond(jsonData, "application/json", context);

// Stream response
API.Respond(fileStream, "image/png", context);

// File response
API.Respond(fileStream, "application/pdf", context);

Advanced request handling

Each endpoint method receives the full HttpListenerContext for complete control:

public void HandleRequest(HttpListenerContext context)
{
    // Read query parameters
    string param = context.Request.QueryString["param"];
    
    // Check HTTP method
    if (context.Request.HttpMethod == "POST")
    {
        // Read POST body
        using (var reader = new StreamReader(context.Request.InputStream))
        {
            string body = reader.ReadToEnd();
        }
    }
    
    // Set custom headers
    context.Response.Headers.Add("Custom-Header", "Value");
    
    API.Respond("Response data", context);
}

Features

  • Zero configuration: No config files or complex setup
  • Production-ready performance: 20k+ req/s capability
  • Concurrent handling: Thread-safe with configurable connection limits
  • Automatic permissions: Handles URL ACL setup with netsh
  • Flexible routing: Simple string-based endpoint mapping
  • Multiple response types: Text, JSON, streams, files
  • Full HTTP access: Complete HttpListenerContext for advanced scenarios
  • Background operation: Server runs on background thread
  • Built-in logging: Timestamped console output for debugging

Requirements

  • .NET Framework
  • Administrator privileges (for URL ACL setup)
  • Available port for listening

Deployment considerations

  • Connection limits: Set based on expected load and available resources
  • Error handling: Implement proper exception handling in endpoint methods
  • Logging: Built-in console logging or integrate with your logging framework
  • Monitoring: Monitor connection count and response times
  • Security: Implement authentication/authorization as needed for your endpoints

Technical architecture

Built on HttpListener with optimized threading model:

  • Semaphore-based connection limiting prevents resource exhaustion
  • Background thread pool handles request processing
  • Automatic Windows URL ACL configuration
  • Direct response streaming for optimal performance

The library prioritizes performance and simplicity over framework features. For applications requiring advanced routing, middleware, or ORM integration, consider full web frameworks. For high-performance HTTP endpoints with minimal overhead, QuickMan delivers production-grade results.

About

Quick way to build self-hosted APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages