axon-web
axon-web
Section titled βaxon-webβAxon HTTP framework β Landing page + M14 framework implementation.
axon-web is the HTTP framework for the Axon ecosystem. It includes:
- A landing page (deployed to GitLab Pages from
public/) - A radix-tree HTTP request router (
tools/router.py) - A composable middleware pipeline (
tools/middleware.py) - Built-in middleware:
RequestLogger,Cors,RecoverFromPanic(tools/builtin_middleware.py) - A static file server (
tools/static_server.py) - A JSON codec (
tools/json_codec.py) - A WebSocket protocol implementation (
tools/websocket.py) - An HTTP/1.1 request parser (
tools/http_parser.py)
Important: public/ is the landing page. It is not the HTTP framework.
M14 Module Index
Section titled βM14 Module Indexβaxon-web ships a growing Python web framework in tools/. Each module
has a dedicated doc in docs/:
| Module | What it does | Doc |
|---|---|---|
router.py | Radix-tree HTTP request router | docs/router.md |
middleware.py | Composable middleware pipeline | docs/middleware.md |
builtin_middleware.py | RequestLogger, Cors, RecoverFromPanic | docs/middleware.md |
static_server.py | Static file server | docs/static-server.md |
json_codec.py | JSON encode/decode | docs/json-codec.md |
websocket.py | WebSocket protocol (RFC 6455) | docs/websocket.md |
http_parser.py | HTTP/1.1 request parser (RFC 7230) | docs/http-parser.md |
template_engine.py | HTML templating (Django/Jinja2-style) | docs/template-engine.md |
html_builder.py | Typed, XSS-safe HTML builder DSL | docs/html-builder.md |
tls.py | HTTPS / TLS termination (OpenSSL FFI) | docs/tls.md |
serve_demo.py | Demo HTTP server | β |
serve_tls_demo.py | Demo HTTP+HTTPS server | docs/tls.md |
Current State
Section titled βCurrent Stateβaxon-web/βββ public/ # Landing page (deployed to GitLab Pages)β βββ index.htmlβ βββ style.cssβ βββ main.jsβββ tools/β βββ router.py # M14: HTTP request router (radix tree)β βββ middleware.py # M14: middleware pipelineβ βββ builtin_middleware.py # M14: built-in middleware (RequestLogger, Cors, RecoverFromPanic)β βββ static_server.py # M14: static file serverβ βββ json_codec.py # M14: JSON codecβ βββ websocket.py # M14: WebSocket protocol (RFC 6455)β βββ http_parser.py # M14: HTTP/1.1 request parser (RFC 7230)β βββ template_engine.py # M14: HTML templating engineβ βββ tls.py # M14: TLS/HTTPS termination (OpenSSL via stdlib ssl)β βββ serve_demo.py # M14: demo HTTP serverβ βββ serve_tls_demo.py # M14: demo HTTP+HTTPS serverβββ tests/β βββ test_router.py # Router tests (28 tests)β βββ test_router_properties.py # Property-based router testsβ βββ test_middleware.py # Middleware testsβ βββ test_websocket.py # WebSocket testsβ βββ ... # Other M14 test suitesβββ docs/β βββ router.md # Router documentationβ βββ middleware.md # Middleware documentationβ βββ websocket.md # WebSocket documentationβ βββ http_parser.md # HTTP parser documentationβ βββ ... # Other M14 docsβββ .gitlab-ci.yml # CI: lint, tests, perf gatesβββ README.md # This fileQuick Start
Section titled βQuick Startβfrom router import Routerfrom middleware import Request, Response
router = Router()
@router.get("/")def home(req): return Response(200, {}, b"hello")
@router.get("/users/:id")def get_user(req): return Response(200, {}, f"user {req.path_params['id']}".encode())
resp = router.dispatch(Request("GET", "/users/42", {}, b""))assert resp.status == 200See docs/router.md for the full router reference.
What This Repo Will Become
Section titled βWhat This Repo Will Becomeβaxon-web implements an HTTP server framework in pure Axon:
- M14 modules: HTTP router (radix tree), middleware pipeline, JSON encoder/decoder, WebSocket protocol upgrade, static file serving, HTML templating, HTTP/2 HPACK + multiplexing, zero-copy request parser, TLS/SSL via OpenSSL FFI
See the M14 Milestone Roadmap below.
Framework Source Layout
Section titled βFramework Source LayoutβThe src/ directory contains the Axon framework modules. These are
type-declared stubs (no runtime implementation yet) that establish the
public API for the M14 framework:
src/βββ router.axs # HTTP request router (radix tree) β axon-web#1βββ middleware.axs # Composable middleware pipeline β axon-web#2βββ json.axs # JSON encoder/decoder β axon-web#3βββ static.axs # Static file server β axon-web#4βββ websocket.axs # WebSocket protocol (RFC 6455) β axon-web#5βββ http_parser.axs # HTTP/1.1 request parser β axon-web#12Each module provides:
- Type declarations (enums, structs, function pointers)
- Public API (
pubfunctions) - Stub implementations that return safe defaults (no-ops, error codes)
The Python prototype of these modules lives in tools/ (e.g., tools/router.py).
The Axon modules are the native implementation; the Python versions
serve as the reference implementation and for property-based testing.
Module APIs
Section titled βModule APIsβrouter.axs (HTTP Request Router)
Section titled βrouter.axs (HTTP Request Router)βrouter.new()βRouterβ Create an empty routerrouter.add(r, method, path, handler)βi32β Register a routerouter.get/post/put/delete/patch(r, path, handler)β HTTP verb sugarrouter.lookup(r, method, path, out_params)βHandlerβ Find a routerouter.set_not_found(r, handler)β Set the 404 handlerrouter.route_count(r)βi64β Number of registered routesrouter.free(r)β Free all memory
middleware.axs (Composable Pipeline)
Section titled βmiddleware.axs (Composable Pipeline)βmiddleware.new()βPipelineβ Create an empty pipelinemiddleware.use(p, mw)β Add a middlewaremiddleware.set_error_handler(p, h)β Set the error handlermiddleware.execute(p, req)βResponseβ Process a requestmiddleware.free(p)β Free all memory
json.axs (Encoder/Decoder)
Section titled βjson.axs (Encoder/Decoder)βjson.decode(input, out_value)βi32β Parse JSONjson.decode_string/int/bool(input, out)β Convenience for primitivesjson.encode(value, out_str)βi32β Serialize JSONjson.encode_string/int/bool(val, out_str)β Convenience for primitivesjson.free(value)β Free a JsonValue treejson.null/of_bool/of_int/of_float/of_stringβ Value constructors
static.axs (Static File Server)
Section titled βstatic.axs (Static File Server)βstatic.validate_path(path)βi32β Path traversal checkstatic.mime_for_path(path)βstringβ MIME type lookupstatic.file_exists(path)βboolβ File existence checkstatic.file_size(path)βi64β File sizestatic.compute_etag(path, out)βi32β ETag generationstatic.parse_range(header, out_start, out_end)βi32β Range request parsingstatic.list_directory(path, out_entries, out_count)βi32β List dirstatic.try_serve_index(dir, out_path)βi32β Find index.htmlstatic.read_file(path, out_data, out_len)βi32β Read file
websocket.axs (WebSocket Protocol)
Section titled βwebsocket.axs (WebSocket Protocol)βwebsocket.new()βConnectionβ Create a connection (Connecting state)websocket.accept_upgrade(headers, count, out)βi32β Validate and accept upgradewebsocket.parse_frame(buf, len, out)βi64β Parse a frame from byteswebsocket.serialize_frame(frame, out_buf, out_len)βi32β Serialize a framewebsocket.mask_payload(payload, len, mask_key)β XOR masking (involutory)websocket.send_text(conn, msg)βi32β Send a text framewebsocket.send_binary(conn, data, len)βi32β Send a binary framewebsocket.send_ping(conn)βi32β Send a pingwebsocket.send_pong(conn, payload, len)βi32β Send a pongwebsocket.close(conn, code, reason)βi32β Graceful closewebsocket.compute_accept_key(key, out)βi32β RFC 6455 Β§4.2.2websocket.free(conn)β Free connection memory
http_parser.axs (HTTP/1.1 Request Parser)
Section titled βhttp_parser.axs (HTTP/1.1 Request Parser)βhttp_parser.parse_request(buf, len, out)βi32β Parse HTTP request from byteshttp_parser.method_to_string(method)βstringβ Method enum to stringhttp_parser.string_to_method(s, out)βi32β String to method enumhttp_parser.parse_query_params(query, out_params, out_count)βi32β Parse query stringhttp_parser.get_header(req, name)βstringβ Case-insensitive header lookuphttp_parser.has_header(req, name)βboolβ Header existence checkhttp_parser.content_type(req)βstringβ Get Content-Typehttp_parser.is_keep_alive(req)βboolβ Connection persistence checkhttp_parser.free(req)β Free request memory
CI Infrastructure
Section titled βCI Infrastructureβ| Job | Stage | What it lints/tests | Status |
|---|---|---|---|
lint:html | lint | public/*.html via tidy | β οΈ allow_failure |
lint:css | lint | public/**/*.css via stylelint@15.11.0 | β οΈ allow_failure |
lint:js | lint | public/**/*.js via eslint@8.57.0 | β οΈ allow_failure |
pages | deploy | Deploys public/ to GitLab Pages | β Active |
test:axon-e2e | test | Axon golden file tests (activates when .axs files exist) | β³ Dormant |
test:axon-check | test | Axon type checking (activates when .axs files exist) | β³ Dormant |
perf:regression-check | performance | Binary size and compile time gates | β οΈ allow_failure |
Note: The lint jobs validate the landing page in public/, not the HTTP framework. The framework doesnβt exist yet.
M14 Milestone Roadmap
Section titled βM14 Milestone Roadmapβ| Ticket | Module | Priority |
|---|---|---|
| #1 | HTTP request router (radix tree) | Critical |
| #2 | Middleware pipeline architecture | Critical |
| #3 | JSON encoder/decoder | High |
| #4 | Static file serving and caching | High |
| #5 | WebSocket protocol upgrade | High |
| #6 | HTML templating engine | Medium |
| #10 | TLS/SSL termination (OpenSSL FFI) | Medium |
| #11 | HTTP/2 HPACK + multiplexing | Medium |
| #12 | Zero-copy HTTP request parser (SIMD) | Medium |
Running Tests
Section titled βRunning TestsβLanding Page Linting
Section titled βLanding Page Lintingβ# HTMLtidy -q -e public/index.html
# CSSnpx stylelint "public/**/*.css"
# JSnpx eslint "public/**/*.js"Placeholder Python Tests
Section titled βPlaceholder Python Testsβpytest tests/Axon Tests (When M14 Source Exists)
Section titled βAxon Tests (When M14 Source Exists)βaxonc testThe tests/test_router.axs and tests/test_json.axs files are smoke tests
for the framework stubs. They register routes / call encode/decode functions
and verify the stubs donβt crash. As the framework is implemented, these
will grow into full behavioral test suites.
Contributing
Section titled βContributingβSee docs/CONTRIBUTING.md for contributor onboarding, and docs/architecture.md for the planned architecture.
Part of the Axon Ecosystem
Section titled βPart of the Axon Ecosystemβ| Package | Description | Status |
|---|---|---|
| axon-lang | Compiler & runtime | β Active |
| axon-std | Standard library | β Active |
| axon-pkg | Package manager | π§ WIP |
| axon-db | Database drivers | π Planned |
| axon-ui | GUI framework (M11/M12/M19) | π Scaffolding |
| axon-web | HTTP framework (M14) | π Scaffolding |
License
Section titled βLicenseβSee project license file.