Overview

CWeb is a full-stack web framework for building web applications in C. It combines an event-driven HTTP server, routing, templates, static asset delivery, compression, sessions, async networking, and developer tooling in one framework and CLI.

If you want the control and performance characteristics of C without giving up the conveniences of a modern web stack, CWeb is designed for that space.

What CWeb Is

CWeb is not just a lightweight HTTP library. It is a framework for building complete web applications and services with a native C runtime.

At a high level, CWeb gives you:

  • An HTTP server
  • Route handling for pages and APIs
  • A compile-time template system for generating HTML
  • Static file serving with caching and compression
  • Sessions and request/response helpers
  • Async fetch utilities for calling external services
  • Built-in API documentation support through cwagger
  • CLI tooling for builds, page generation, and project scaffolding

The goal is to let you build real web applications in C without assembling every subsystem yourself.

Why CWeb

Most C web stacks stop at request parsing or routing. CWeb goes further by providing the parts that are usually missing when you try to build a full application:

  • HTML rendering with typed templates (templates get compiled to c code for perfomance)
  • Project-structure-based route generation
  • Static assets and cache management
  • Compression and response optimization
  • Sessions, logging, leak tracking, and benchmarking
  • A CLI that participates in the build pipeline

This makes CWeb a practical choice for developers who want low-level control, predictable runtime behavior, and a more integrated developer experience than a collection of unrelated C libraries.

Core Capabilities

Native HTTP Runtime

CWeb runs on an event-driven server architecture based on libevent. It includes request parsing, response serialization, route matching, header management, and support for asynchronous response flows.

Compile-Time Templates

CWeb templates are written as .cweb files. During cweb build, they are compiled into normal C source files and linked into your application.

This gives you:

  • Native performance characteristics
  • Strong integration with C types
  • No separate template runtime to interpret files on every request
  • The ability to mix HTML with real C control flow

Routing and Project Integration

CWeb can generate routes from your project structure, reducing boilerplate for page-oriented applications. Templates, routes, and generated code fit into a conventional app layout and build cleanly with CMake.

Static Files, Caching, and Compression

The framework includes a built-in file server with multiple serving modes, asset caching, MIME type handling, and automatic compression with Brotli and Gzip.

This is useful when you want one runtime to serve:

  • HTML pages
  • JSON APIs
  • CSS, JavaScript, fonts, and images

Async Networking

CWeb includes an async fetch system for outgoing HTTP requests. That makes it possible to integrate external APIs, services, or internal HTTP-based components without leaving the framework.

Developer Tooling

CWeb includes tools that matter in real projects:

  • Structured logging
  • Leak tracking
  • Request speed benchmarking
  • Session handling
  • Built-in API documentation support

These features are especially valuable in C projects, where observability and memory discipline are part of day-to-day development.

How It Works

In a typical CWeb project:

  1. You define routes and page handlers in C.
  2. You write .cweb templates for HTML output where needed.
  3. The cweb CLI compiles templates and generates build artifacts.
  4. CMake builds the generated sources together with your application code.
  5. The final result is a native executable that serves pages, APIs, and assets.

This model keeps the application close to normal C development instead of introducing a large interpreted runtime layer.

What You Can Build

CWeb is a good fit for:

  • Server-rendered websites
  • Documentation sites
  • Admin panels and internal tools
  • JSON APIs and backend services
  • Hybrid apps that serve both pages and APIs
  • Performance-sensitive self-hosted applications
  • Systems where a native C deployment model is a feature, not a constraint
  • high perfomance landing pages

Because CWeb includes templates, routing, static delivery, and async HTTP support, it works well for applications that need both frontend output and backend logic in the same codebase.

When CWeb Makes Sense

Choose CWeb when you want:

  • A lot of automatisations and easy to use functionalitys without loosing control thanks to modular design
  • A native web stack without a heavyweight VM or interpreter
  • Tight performance characteristics
  • A unified framework instead of wiring together many separate C libraries
  • A build-driven workflow that turns templates into compiled code
  • A WebFramwork that is not like another typical Framework. it focus on problems of generic frameworks.

Mental Model

If you are new to CWeb, the simplest way to think about it is:

CWeb brings the structure of a modern web framework to native C applications.

You still work with real C code, real compilation, and real system-level control. The difference is that routing, HTML generation, static assets, compression, async fetch, and documentation support are already part of the framework.

In Practice

CWeb is designed for developers who want to ship fast native web applications while keeping the advantages of C:

  • explicitness
  • performance
  • low overhead
  • deployment simplicity
  • deep control over behavior

If your project needs a perfomance full stack web framework that stays close to the machine but still feels like an application framework, CWeb is the layer that provides that structure.

Contribution

if you like this project check out the github repo and you may like to contribute