Skip to content

srdjan/zigttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,026 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

zigttp

Website - Documentation

zigttp

zigttp is a pure-Zig JavaScript and TypeScript runtime for HTTP handlers. It ships as one binary, runs without npm or Node, and uses a restricted language profile so the compiler can prove useful handler properties before the server starts.

The daily workflow is small:

zigttp init my-app && cd my-app
zigttp dev
zigttp test
zigttp deploy

zigttp dev watches the handler, recompiles it, and prints a proof card on every save. zigttp deploy builds a self-contained local binary, writes a proof ledger entry, and signs a proof receipt by default.

Install

Pre-built binaries are published for macOS and Linux on x86_64 and aarch64:

curl -fsSL https://raw.githubusercontent.com/srdjan/zigttp/main/install.sh | sh

Or build from source with Zig 0.16.0:

git clone https://github.com/srdjan/zigttp.git
cd zigttp
zig build -Doptimize=ReleaseFast

First Handler

import type { Spec } from "zigttp:types";

type Guardrails = Spec<
    | "deterministic"
    | "no_secret_leakage"
    | "injection_safe"
>;

function HomePage(): JSX.Element {
    return (
        <html>
            <head><title>Hello</title></head>
            <body><h1>Hello from zigttp</h1></body>
        </html>
    );
}

function handler(req: Request): Response & Guardrails {
    if (req.path === "/") {
        return Response.html(renderToString(<HomePage />));
    }
    if (req.path === "/api/echo") {
        return Response.json({ method: req.method, path: req.path });
    }
    return Response.text("Not Found", { status: 404 });
}

See examples/ for routing, JSX/TSX, SQL, fetch, durable workflows, WebSocket, and proof examples.

Current Surface

  • Five core commands: init, dev, test, expert, deploy. Advanced commands are listed by zigttp help --all.
  • Handler API: function handler(req): Response, plus Response.text, Response.json, and Response.html.
  • Language profile: a restricted JS/TS/TSX subset with no var, while, class, or try/catch; unsupported constructs fail at compile time.
  • Proofs: response-path verification, Result/optional checks, state-isolation checks, active Spec<...> obligations, flow checks, proof traces, witnesses, and proof receipts.
  • Virtual modules: 22 native modules under zigttp:* for env, crypto, auth, validation, cache, SQL, fetch, service calls, WebSocket, routing, durable workflows, structured I/O, logging, IDs, time, text, and more.
  • Local deploy: self-contained binary output under .zigttp/deploy/<project-name> with default-on attestation.

Numbers

Benchmark claims are kept in Performance. The measured baseline is roughly a 3.5 ms cold-start floor, 7-15 ms typical cold start depending on host load, about 13 MB RSS after first response, and about 112k req/s on the documented HTTP benchmark.

Documentation

Start at the Documentation Index.

Contributing

See CONTRIBUTING.md. Security reports go through SECURITY.md.

License

MIT.

About

Native Zig TypeScript runtime that started as port of mquickjs to Zig... and... grew up to something bigger

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages