htxlang Specification

Version 0.2 Jared Foy April 2026


Status

Working draft. This document specifies the contracts and mechanics of the htxlang specification as derived from the PRESTO architectural style.

1. Introduction

This specification defines the contracts that a conformant htxlang engine must satisfy. It specifies what must be true of the input, the output, the resolution process, and the extension contracts between them.

The key words MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY in this document are to be interpreted as described in RFC 2119.

1.1 Relationship to PRESTO

The PRESTO architectural style extends Representational State Transfer (REST) by formalizing code-on-demand as a progressive spectrum. This specification describes contracts through which a server engine may realize the PRESTO style. The style is independent of this specification.

1.2 Scope

This specification defines eight contracts. Each specifies what a conformant engine MUST satisfy. How the engine satisfies each contract is an implementation decision unless a specific mechanic is normatively required.


2. The Document Model

2.1 Source Representation

The input to a conformant engine is a source representation: an HTML document augmented with server directives in a designated namespace.

A conformant engine MUST define a server namespace that is syntactically distinguishable from standard HTML elements and attributes. All directives within this namespace are server affordances.

2.2 Namespace Requirements

The server namespace MUST satisfy:

2.3 Resolved Representation

The output of a conformant engine is a resolved representation: a complete HTML document in which all server directives have been consumed.

A conformant engine MUST produce output that:

2.4 Bilateral Property

The source representation is bilateral: it carries both server affordances and client affordances within a single artifact.

The resolution process transforms the bilateral source into a unilateral resolved representation. The transformation is one-directional: the resolved representation carries only client affordances.

2.5 Script Element Opacity

Content within HTML <script> elements is client territory.

A conformant engine MUST NOT:

This requirement is absolute. Implementations MUST NOT provide a mechanism to override it for standard <script> elements. Server-mediated scripts (§3.8) are a separate construct within the server namespace.

2.6 Literal Blocks

A conformant engine MUST provide a mechanism to declare regions of the source representation as literal. Content inside literal blocks MUST NOT be processed by the expression evaluator or any directive resolver. Literal blocks pass through resolution as-is, with only the literal block markers removed from the output.


3. The Resolution Contract

3.1 Overview

Resolution is the process of transforming a bilateral source representation into a unilateral resolved representation. The engine reads the source, processes all server directives, and produces HTML.

A conformant engine MUST perform resolution as an ordered sequence of stages. The specification does not prescribe the number or naming of stages, but the following processing requirements MUST be satisfied, and the ordering constraints between them MUST be observed.

3.2 Ordering Constraints

The following ordering constraints are normative:

Implementations MAY introduce additional stages, merge stages, or reorder stages, provided all ordering constraints are satisfied and the output is identical to a conformant sequential implementation.

3.3 Inclusion

A conformant engine MUST support including the content of one template file within another.

Mechanics:

3.4 Composition

A conformant engine MUST support reusable template fragments (components).

Mechanics:

Parameter resolution:

Script scoping:

3.5 Variable Binding

A conformant engine MUST support declaring named variables within the source representation.

Mechanics:

3.6 Data Binding

A conformant engine MUST provide a mechanism for declaring data requirements within the source representation.

Mechanics:

Single-record mode:

Multi-record mode:

Multiple data directives:

3.7 Layout Wrapping

A conformant engine MUST support wrapping resolved content in layout templates.

Convention-based discovery:

Directive-based override:

Fragment mode:

3.8 Server-Mediated Scripts

A conformant engine MUST provide a mechanism for scripts that participate in server resolution while being delivered to the client as executable code.

Mechanics:

Expression evaluation in scripts:

Component-level scripts:

Page-level scripts:

3.9 Script Injection

Collected scripts (from both component and page-level extraction) MUST be injected into the resolved representation.

Mechanics:

3.10 Expression Evaluation

A conformant engine MUST provide a mechanism for embedding server-resolved values in the document.

Path resolution:

Pipe functions:

Escaping:

Attribute expressions:

3.11 Directive Stripping

After all resolution stages, a conformant engine MUST remove any remaining server namespace directives from the document. The resolved representation MUST contain no server namespace content.

3.12 Idempotence

Resolving a resolved representation (one that contains no server directives) MUST produce identical output. Resolution is idempotent on fully-resolved documents.


4. The Grant Contract

4.1 Purpose

Grants materialize capability credentials into the resolved representation. The grant makes the authority chain visible: the developer declares what the template authorizes, and the engine materializes the proof.

4.2 Grant Directive

A conformant engine MUST support a grant directive within the server namespace. The directive specifies:

4.3 Credential Requirements

A materialized grant MUST produce an object in the data context containing at minimum:

4.4 Credential Properties

Credentials MUST be:

4.5 Scope

Credentials SHOULD be scoped to a specific resource or channel. A credential issued for one purpose SHOULD NOT grant access to unrelated resources.

4.6 Built-in Grant Types

A conformant engine SHOULD support:

Implementations MAY support additional grant types via the extension contract (§6).


5. The Mutation Contract

5.1 Purpose

Mutations are write operations (create, update, delete) that modify server-side data. The mutation contract ensures that writes are authorized, stateless, and resistant to forgery.

5.2 Action Directive

A conformant engine MUST support an action directive within the server namespace. The directive specifies:

5.3 Token Generation (Prepare Phase)

During resolution of a GET request, the engine MUST:

  1. For each action directive, generate a signed token encoding the action name, resource type, record identifier (if present), and an expiration timestamp.
  2. Inject the tokens into the data context under a well-known path (e.g., $actions.{name}).
  3. Remove the action directive from the output.

The developer embeds the token in a form as a hidden field, making it available for the execute phase.

5.4 Token Verification (Execute Phase)

When the server receives a POST request containing a mutation token, the engine MUST:

  1. Extract the token from the request body.
  2. Verify the token's cryptographic signature.
  3. Verify the token has not expired.
  4. Extract the action name, resource type, and record identifier from the token payload.
  5. Execute the mutation through the content adapter or a registered handler.
  6. If verification fails at any step, reject the mutation. The engine MUST NOT execute the write.

5.5 Statelessness

The mutation token MUST encode all information necessary for verification and execution. The server MUST NOT maintain state between the prepare and execute phases. The token is self-contained.

5.6 Token Format

The token MUST consist of a payload and a signature. The payload MUST include at minimum:

The encoding format (Base64, Base64URL, etc.) and signing algorithm (HMAC-SHA256, Ed25519, etc.) are implementation choices, provided the signature is cryptographically secure.


6. The Extension Contract

6.1 Purpose

The extension contract allows third-party and first-party code to extend the engine's capabilities without modifying the engine itself.

6.2 Module Interface

A module is a unit of extension. A conformant engine MUST define a module interface comprising:

6.3 Trust Levels

A conformant engine MUST support at least two trust levels:

Implementations MAY define additional trust levels (e.g., marketplace, tenant) with progressively narrower access.

6.4 Registry

The registry is the interface through which modules register capabilities. A conformant engine MUST support registration of:

Implementations MAY support additional registration types.

6.5 Manifest Enforcement

For restricted modules, the engine MUST enforce the manifest:

6.6 Boot Lifecycle

Modules are booted during engine startup, before the engine begins accepting requests. A conformant engine MUST:

  1. Accept an ordered list of modules.
  2. For each module, read its manifest and determine the appropriate trust level.
  3. Provide a registry (or sandboxed proxy) to the module's boot function.
  4. Call the boot function.
  5. If the boot function throws an error, the engine MUST log the error and continue booting remaining modules. One module's failure MUST NOT prevent other modules from booting.

7. The Channel Contract

7.1 Purpose

Channels provide authenticated HTTP endpoints through which delivered client code accesses server data. They are the bridge between progressive code-on-demand and server-side resources.

7.2 Endpoint Pattern

A conformant engine MUST expose channel endpoints at a well-defined URL pattern. The pattern MUST include the module name and a sub-path:

{base}/channel/{module}/{subpath}

The {base} prefix is an implementation choice (e.g., /api).

7.3 Authentication

Channel requests MUST carry a credential. The credential format is an implementation choice, but the engine MUST validate it before routing the request.

A conformant engine MUST verify:

  1. Signature validity. The credential's cryptographic signature is correct.
  2. Expiration. The credential has not expired.
  3. Scope. The credential's scope matches the requested module. A credential issued for module A MUST NOT grant access to module B.

If any verification step fails, the engine MUST return an error response and MUST NOT route the request to the handler.

7.4 Handler Interface

A channel handler receives:

The handler returns:

The engine serializes the response data (typically as JSON) and returns it to the client.

7.5 Token Refresh

Channel credentials are time-limited (§4.4). A conformant engine SHOULD provide a mechanism for the client to refresh an expiring credential without re-establishing the full delivery ceremony. This MAY be a dedicated refresh endpoint or a convention within the channel handler.


8. The Delivery Contract

8.1 Purpose

Delivery is the mechanism by which the server provides executable code to the client as a granted capability. The server controls what code is delivered. The client does not choose what to download.

8.2 Compilation

A conformant engine MUST compile delivery payloads from source files. The compilation MUST occur on the server, not on the client.

8.3 Delivery Payload

A delivery payload MUST include:

8.4 Transport

A conformant engine MUST support at least one delivery transport:

A conformant engine SHOULD support HTTP delivery at minimum, as it requires no persistent connection.

8.5 Client Execution

Delivered code is executed on the client with injected globals:

The specific execution mechanism (e.g., Function constructor, module evaluation) is an implementation choice.

8.6 Ephemeral Delivery

A conformant engine MAY support ephemeral delivery: a transport connection that opens, delivers one or more payloads, and immediately closes. This pattern is consistent with the PRESTO style but is not required.


9. The Security Contract

9.1 Security Through Absence

The primary security property is absence. Capabilities that the server does not grant do not exist on the client.

A conformant engine MUST NOT include in the resolved representation:

9.2 Expression Escaping

Server-resolved values embedded in HTML content MUST be HTML-escaped by default. The following characters MUST be escaped:

Character Replacement
< &lt;
> &gt;
& &amp;
" &quot;

The engine MUST provide an explicit opt-in mechanism for unescaped output. Unescaped output MUST NOT be the default.

9.3 Credential Security

All credentials produced by the engine (mutation tokens, channel tokens, signed URLs, connection tokens) MUST be:

9.4 Script Isolation

The engine MUST NOT process content within standard HTML <script> elements (§2.5). This prevents:

9.5 Path Traversal Prevention

The engine MUST reject file paths containing .. in:

Paths that resolve outside the template root directory MUST be rejected regardless of whether they contain ...

9.6 Content Security

The engine SHOULD set appropriate security headers on responses:

These headers are implementation-level recommendations, not specification requirements.


10. Conformance

10.1 Conformance Levels

A fully conformant engine satisfies all MUST requirements across all eight contracts.

A partially conformant engine satisfies all MUST requirements in contracts 1-3 (document model, resolution, security) and documents which additional contracts it supports.

10.2 Extensions

A conformant engine MAY extend the specification with additional features, provided:

10.3 Versioning

This specification is versioned. Implementations SHOULD declare which version they conform to.


References

  1. Fielding, R.T. (2000). Architectural Styles and the Design of Network-based Software Architectures. Doctoral dissertation, University of California, Irvine.

  2. Foy, J. (2026). An Architectural Style for Progressive Representational State Transfer with On-Demand Code. Working paper.

  3. Bradner, S. (1997). Key words for use in RFCs to Indicate Requirement Levels. RFC 2119.