DocsCustom actions · FRL
On this page

Create a custom endpoint

Declare an endpoint and read request data.

FRL endpoints let a theme expose small JSON routes for workflows that do not fit a normal createPost, updatePost, or deletePost call.

Use them for checks, calculators, action buttons, callback-style workflows, and controlled operations where the rule file should decide what is accepted and what response is returned.

Basic Endpoint

backend/index.frl
Rule input (JSON)

Use a complete version 2 rule file. Select a post with “postType” and “action”, or an “endpoint” by name. Saved data, jobs, payments and email need the local server. Dedupe replay protection also needs a site.

Check complete rules or run schemas, permissions, hooks and calculations against the input above. Add excerpts to a complete rule before running.

Call it from the theme by its endpoint name:

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

The browser receives the object returned by the endpoint body. If the returned value is not an object, Frontbacked wraps it as { ok: true, result }.

Endpoint calls require a signed-in visitor by default. Set allowGuest: true when the endpoint should accept guests. If the visitor is signed in, Frontbacked includes their authentication in either case. Direct HTTP clients and webhook senders can still call the endpoint path at /fb-endpoints/leads/submit.

Endpoint Syntax

frl

Rule excerpt: add this to a complete FRL rule before running it. Try a complete example →

PartPurpose
methodOne of get, post, put, patch, or delete.
endpointNameA unique name for this endpoint in the rule file.
"/path/:param"Public path under /fb-endpoints. Params can use :id or {id}.
as "Friendly endpoint label"Optional UI label exposed as endpoint.<name> metadata. It does not change the endpoint name, method, path, or how the route is called.
must(expression, message?, status?)Assertion for required values. A falsy value stops the endpoint.
mustNot(expression, message?, status?)Optional inverse assertion. A truthy value stops the endpoint.
dedupeOptional stable key that makes repeated matching requests safe.
Endpoint statementsAssign $context, call helpers, and return a JSON response directly inside the endpoint block.

FRL uses allow for post action/list permissions and must(...) or mustNot(...) for endpoint and hook assertions. A failed assertion stops the rule run; when a second argument is provided, it becomes the error message. A third argument can set the HTTP status returned to the caller and must resolve to an integer from 400 to 599.

Use aliases when admin tools need a clearer label than the endpoint name. Comments remain normal comments; they are not used for endpoint labels in FRL v2.

backend/index.frl
Rule input (JSON)

Use a complete version 2 rule file. Select a post with “postType” and “action”, or an “endpoint” by name. Saved data, jobs, payments and email need the local server. Dedupe replay protection also needs a site.

Check complete rules or run schemas, permissions, hooks and calculations against the input above. Add excerpts to a complete rule before running.

Request Data

Endpoint rules read request data through $request.

ValueExample
Method$request.method
Matched path$request.path
Declared endpoint path$request.endpointPath
Path params$request.params.slug
Query params$request.query.plan
Parsed body$request.body.email
Raw body text$request.rawBody
Headers$request.headers["content-type"]

Endpoint $request is intentionally narrow. It does not include the full URL, origin, hostname, site domain, cookies, authorization tokens, or forwarding/IP headers.

Other familiar FRL values are also available: $actor, $admin, $secret, $page, $currency, $context, and local fn helpers.

Continue with Call an endpoint from a page.