Skip to main content
A portal function is a declared host capability callable by a widget worker. Import functions from @fluid-app/portal-sdk/widgets/worker and declare every function the widget uses. The callable exports are under Variables in the Widget Worker SDK Reference.

Declare each function in uses

Call the same typed function values from the component. Do not maintain a parallel string list of capability names. The worker and host enforce the uses declaration.

Choose a capability family

The public worker facade provides functions for:
  • portal navigation, links, fullscreen, account, store, and profile state;
  • content, catalog, media, metric, and calendar reads;
  • content, playlist, share, and DAM mutations;
  • member access, points, todos, account updates, and MySite data.
Use each linked generated declaration for the function’s exact input, result, error behavior, and required uses declaration. For example, see getPortalProfile and navigateTo.

Handle errors and partial data

Treat results as documented SDK values and do not assume undocumented fields are present. Handle unavailable, missing, partial, and malformed values without throwing during render. See PortalFunctionError for the supported error codes.

Give a widget its own backend

A widget has no server, database or secrets of its own. When it needs its own data model or API, put that in a server app, such as a Mist app, which comes with hosting and a Postgres database. The widget then reaches the server through a portal function that your portal implements. The worker can’t call the server directly. Even with network access, a widget’s requests to fluid.app addresses, including Mist app addresses, are blocked. So the call runs in the portal, which owns the handler.
1

Define the function

Define it once, in a module that both the widget and the portal import. Inputs and outputs must be JSON values.
2

Call it from the widget

Add the function to the widget’s uses, then call it like any other portal function.
3

Implement it in the portal

In the portal project’s src/main.tsx, pass a handler for the function to createPortal. The handler calls your server.
Keep secrets on the server, never in the portal code. Your server receives requests from the portal page, so it must allow your portal’s address and check every request itself. See Mist app authentication. A custom function works only in a portal that implements it. This pattern suits a company package, whose widgets and portal live in the same project. In a portal without the handler, the call rejects with a PortalFunctionError, so render a useful unavailable state.