Explore the features

Give the page an explicit service boundary.

An endpoint is a declared page method that returns data. dataRpc connects its answer to the page.

A guided reading · 2 min

Start with a question the browser cannot settle.

A page may need a price calculated by a service, a permission-dependent result or information held by a host. Declare that operation as an endpoint and call it through dataRpc. The returned value can be written into Data and shown through ordinary bindings.

The page author describes the method, inputs and result path instead of building a separate fetch protocol for each control.

A complete small Python example.

This example follows the public guide. It demonstrates the call, not production tax or currency rules. The Python method accepts **kwargs because dataRpc forwards the authored arguments. The response is a value, not executable interface code.

Python · explanatory excerpt
from gramlot import Page as BasePage, endpoint

class Page(BasePage):
    def main(self, root):
        root.input(type="number", value="^.price")
        root.dataRpc(
            "with_vat", result_path=".gross",
            price="^.price",
            _onError="console.warn(error.message)"
        )
        root.span("^.gross")

    @endpoint
    def with_vat(self, price, **kwargs):
        return round((price or 0) * 1.22, 2)

Read the explanation here. The working lesson and full contract are linked below.

Give failures a place in the experience.

dataRpc supports a timeout, _onResult and _onError. Only one request runs at a time. Its answer is applied; the first trigger received while it runs waits with its arguments. Later triggers are ignored while one is waiting. Removing the declaration aborts its call. Rapid edits can leave the result behind current inputs until another trigger; identify which inputs produced a confirmed result. An unknown method and an application exception have explicit error outcomes.

The example logs failures for teaching. A finished application should explain failure and any next action in its interface. Aborting a browser call does not establish a transaction rollback policy for business operations on a server.

A page endpoint is not an invented REST route.

Calls travel through the shared Gramlot RPC envelope. @endpoint marks a callable method; it does not automatically publish a separate URL named after that method. An arbitrary external JSON service is a different integration, for which sendHttp provides a data handoff.

Protected endpoints use auth rules evaluated by a capable host. A host without authentication refuses protected calls. Do not use a browser Worker to hold secrets or enforce trusted server permissions.

Try the working example and read the full contract

Open the Python lesson (c09) ↗
Official documentation ↗