Minimal HTTP Server

Home > Solutions > Minimal Rust HTTP Server

Lightweight, self-contained HTTP server and JavaScript Runtime built in Rust. It allows you to write "Express.js"-like API's and serve static files without needing to install Node.js or even npm. Everything runs from one portable .zip folder.

Designed for you to test our API's and Solutions locally with on any machine. Compatible projects:

HTTP methods:

  • GET - parsing query parameters from URL calls, accepts JSON body, calls dispatch(req, res) in JS
  • POST - parsing query parameters from URL calls, accepts JSON body, calls dispatch(req, res) in JS
  • Others - not implemented (404)

Pre-built package

Just one simple .zip that contains everything

If you prefer to build the server on your own

Clone the GitHub repository, then refer to the build section

JavaScript API Examples:

Router:


import {getStatus} from './services/status.js'

const routes = {
    'GET /status': getStatus
    //...
};

export function dispatch(req, res) {
    const routeKey = `${req.method} ${req.path}`;
    const handler = routes[routeKey];

    if (handler) {
        handler(req, res);
    } else {
        res.status = 404;
        res.body = {error: `No handler for ${routeKey}`};
    }
}

Endpoint function:


export function getStatus(req, res) {
    const {
        name,
        address    
    } = req.body;
    //...
    res.body = {
        address: `Your address is ${address}` ,
        name: `Hi ${name}`
    };
}

Key Features:

  • Portable - just run the .exe file
  • Fast HTTP server using tiny_http
  • Custom JavaScript runtime using boa
  • Hot reload - live JS file watching and automatic bundling with esbuild
  • Logging
  • Minimal backend framework built to mimick Express.js

Solution structure

├── backend/ # JavaScript code (entry = logic/index.js)
├── dist/ # Auto-bundled JS output and static files
├── esbuild.exe # Local esbuild binary for bundling
├── src/
│ ├── main.rs # App entry point
│ ├── server.rs # HTTP request handler
│ ├── serve_static_files.rs # Serving static HTML, CSS, JS
│ ├── js_engine.rs # JS runtime loader (Boa)
│ ├── watcher.rs # JS file watcher + esbuild bundler
│ └── utils.rs # Common helpers (responses, query parsing, etc.)

Building the server on your own:


cargo build --release

After you are done building, go to ./target/release/backend_server , copy over /backend, /dist and esbuild.exe . 

You are now ready to run the backend_server.exe and build your API inside /backend