Skip to content

redpeacock78/H-awk

Repository files navigation

H-awk

CI License: MIT Ask DeepWiki

Write backends in plain AWK. No Node. No Python. No compiled binaries.


Features

  • Express-like routinghawk.app.get, .post, .del, and friends
  • Type-safe DSLlet, when...of, ??, |>, and compile-time type annotations
  • Typed collectionsList<T>, Dict<K, V>, Record (JSON-aware)
  • URL helperslibs/url Zig-backed URL encode/decode with AWK fallback
  • JSON helperslibs/json Zig-backed JSON encode/decode; typed ctx.res.json(List<Todo>)
  • Gzip compressionlibs/gzip HTTP response compression; HAWK_GZIP=1 to enable
  • XSS-safe by design — brand types make unsafe HTML a desugar-time error
  • Multi-workerSO_REUSEPORT + HTTP/1.1 keep-alive via optional Zig extensions

Quick Start

Requirements: gawk 5.0+, bash 4.3+, GNU make

cp .env.example .env
./bin/hawk app.awk        # Start on :8080 (multi-worker requires libs/net)
curl http://localhost:8080/
curl -X POST -d 'title=buy+milk' http://localhost:8080/todos
curl -X DELETE http://localhost:8080/todos/1234
BEGIN {
  hawk.app.get("/todos", "list_todos")
  hawk.app.post("/todos", "add_todo")
  hawk.app.listen(8080)
}

function list_todos() {
  let rows = []
  let n: Int = read_tsv("data/todos.tsv", rows)
  let payload = []
  payload["count"] = n
  return ctx.res.json(payload)
}

function add_todo() {
  when ctx.req.form("title") of
    ok raw:
      ctx.res.status(201)
      return ctx.res.html(safe.html.fragment(
        "<li>", safe.html.escape(raw), "</li>"
      ))
    ng:
      ctx.res.status(400)
      return ctx.res.text("title required")
  end
}

Documentation

Setup & Installation Requirements, build-libs, fetch-libs
CLI Reference Subcommands and flags
Routing Route registration, router files
DSL Reference let, when...of, ??, `
API Reference Context API, request/response, env::
Plugins Plugin hooks, submodule distribution
Native Extensions Zig libs, cache API, multi-worker
Testing Test targets and CI

MIT © redpeacock78 · 🌐 日本語

Releases

No releases published

Packages

 
 
 

Contributors