An attempt at a super-simple, super-easy C++ web framework
Find a file
2025-10-07 23:04:56 -05:00
bench namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
include/sockets namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
src namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
.gitignore add http parser benchmark 2025-10-07 11:01:46 -05:00
example.cpp namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
Makefile namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
README.md namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00
sushi.hpp namespacing, dist prep, etc 2025-10-07 23:04:56 -05:00

🍣 Sushi - Fast C++ Web Framework

A modern, high-performance C++20 web framework for building HTTP/1.1 servers.

Quick Start

#include "sushi.hpp"

int main() {
    sushi::Server app("0.0.0.0", 8080);

    app.GET("/", [](sushi::Context& ctx) {
        ctx.text("Hello, Sushi! 🍣");
    });

    app.GET("/api/users/:id", [](sushi::Context& ctx) {
        auto id = ctx.param("id");
        ctx.json("{\"user\":\"" + std::string(id) + "\"}");
    });

    app.listen();
    return 0;
}

Compile and run:

make
./example

Features

  • Fast: Zero-copy I/O, epoll-based event loop
  • Modern: C++20, clean API with lambdas
  • Simple: Single header include (sushi.hpp)
  • Complete: Routing, JSON, static files, keep-alive
  • Scalable: Multi-process worker support

Using in Your Project

Yes! Just copy and paste the sushi directory:

# Copy sushi directory to your project
cp -r /path/to/sushi ./your_project/

# Build sushi once
cd your_project/sushi && make

# In your code
#include "sushi/sushi.hpp"

# Compile
clang++ -std=c++20 -I./sushi your_app.cpp \
    sushi/src/http/context.o \
    sushi/src/http/listener.o \
    sushi/src/http/parser/http_parser.o \
    sushi/src/router/router.o \
    sushi/include/sockets/*.o \
    -pthread -o your_app

See INTEGRATION.md for more integration options (system install, CMake, etc.).

API Overview

Server

sushi::Server app("0.0.0.0", 8080);

Routes

app.GET("/path", handler);
app.POST("/path", handler);
app.PUT("/path", handler);
app.DELETE("/path", handler);
app.PATCH("/path", handler);

Context Methods

// Request
ctx.method()          // HTTP method
ctx.path()            // URL path
ctx.param("key")      // Route parameter
ctx.query("key")      // Query parameter
ctx.header("key")     // Request header
ctx.body()            // Request body

// Response
ctx.text(body, status)
ctx.json(body, status)
ctx.html(body, status)
ctx.send(status, body, content_type)
ctx.set_header(key, value)

Route Parameters

app.GET("/users/:id", [](sushi::Context& ctx) {
    auto id = ctx.param("id");
    ctx.json("{\"user_id\":\"" + std::string(id) + "\"}");
});

Static Files

sushi::StaticFileServer static_server("./public");
app.serve_static("/static/*filepath", &static_server);

Requirements

  • C++20 compiler (clang++ or g++)
  • Linux/Unix (uses epoll)
  • pthread

Building

make          # Build example
make clean    # Clean build
make dist     # Create distribution package
make install  # Install system-wide (requires sudo)

Performance

Sushi is designed for high performance:

  • Radix tree routing (O(k) lookup, k = path length)
  • Zero-copy static file serving with sendfile()
  • HTTP/1.1 keep-alive and pipelining
  • Multi-process workers
  • Minimal allocations