zedocs
GitHub ↗
Build with Ze

Web applications

Build and serve Ze web applications with HTTP routes and automatic reloading.

Modular applications

Run ze serve from a folder containing server.ze and schema.sql. ze start is an alias. Ze loads the application’s modules, initializes SQLite, and starts listening on localhost:8080.

ze serve
ze serve --port 9000
ze serve --host 127.0.0.1 --port 8081 --db other-database.db
ze serve --entry path/to/server.ze --schema schema.sql
ze serve --help

Use --addr host:port to override the host and port together. Database and schema paths are relative to the entry file. Watch mode automatically reloads edited .ze files and imports; use —watch=false to disable it. Configuration and schema changes require a restart. Ctrl+C shuts down the server and closes SQLite. On Windows without Ze on PATH, use the executable path, such as ..\Ze\bin\ze.exe serve.

The following sections describe the separate -web page-serving mode.

Ze can serve .ze files directly as HTTP request handlers. Each incoming request gets its own fresh interpreter instance — no shared state between requests.


Starting the Server

Ze -web
Ze -web -dir ./pages
Ze -web -dir ./pages -addr 0.0.0.0:3000
FlagDefaultDescription
-web—Enable web server mode
-direxamplesRoot directory containing .ze page files
-addrlocalhost:8080TCP address to listen on

URL Routing

Files are auto-discovered when the server starts and mapped to URL paths by stripping the root directory and the .ze extension:

pages/index.ze        ->  GET /
pages/about.ze        ->  GET /about
pages/contact.ze      ->  GET /contact
pages/api/users.ze    ->  GET /api/users
pages/404.ze          ->  catch-all 404 handler

Request Built-ins

These functions are injected into every web-mode .ze file. They are not available in regular file or REPL mode.

Reading the Request

FunctionReturnsDescription
get_method()stringHTTP method: "GET", "POST", "PUT", "DELETE", etc.
get_path()stringRequest URL path, e.g. "/api/users"
get_param(name)string / nothingValue of a URL query parameter (?name=value)

Sending a Response

FunctionDescription
respond(text)Send a plain-text body with Content-Type: text/plain
respond_html(html)Send an HTML body with Content-Type: text/html
respond_json(value)Serialize value to JSON and send with Content-Type: application/json
set_status(code)Set the HTTP status code (call before respond*)
set_header(name, value)Set a response header
redirect(url)Send a 302 redirect to url

Examples

Plain Text Response

# pages/hello.ze
set name = get_param("name")
if name is nothing:
    set name = "World"
respond("Hello, " + name + "!")

Visit http://localhost:8080/hello?name=Zyron -> Hello, Zyron!

HTML Page

# pages/index.ze
respond_html("
<html>
  <body>
    <h1>Kamusta!</h1>
    <p>Welcome to Ze Web.</p>
  </body>
</html>
")

JSON API

# pages/api/status.ze
set data = "ok"
respond_json(data)

Returns: "ok" with Content-Type: application/json

Method Check

# pages/form.ze
if get_method() is "POST":
    respond_html("<p>Form submitted!</p>")
else:
    respond_html("
    <form method='POST'>
        <input name='username'>
        <button>Submit</button>
    </form>
    ")

404 Handler

Create pages/404.ze — it is automatically used for any path that has no matching file:

# pages/404.ze
set_status(404)
respond_html("<h1>Page not found.</h1>")

Notes

  • Each request runs the .ze file from scratch; there is no persistent server-side state between requests.
  • The file is re-read from disk on every request, so edits take effect immediately without restarting.
  • All regular Ze built-ins (split, upper, num, math functions, etc.) are available alongside the web built-ins.
Help make these docs better.Edit this page on GitHub ↗

Find a guide or search the language reference.