Skip to main content

Use sendRequestToBitfieldTarget(...) when app code needs to ask a named Bitfield target to do work.

What this is

A target is a public callable name. Your app sends a payload to that name. Runtime Kit routes the payload to the package code registered for that target. Your app receives reply bytes.

The mental model

Your app should not care how the work is performed. It should care about the public action name and the payload it sends.If a user clicks a search button, your app can call product.search. The package behind that target can change later. Your button can stay the same as long as the action reply shape stays the same.That is the value: app code calls the public target name, not the private implementation.

How it works technically

read

useBitfieldData(...) reads values already prepared for the surface.

act

sendRequestToBitfieldTarget(...) sends bytes to a named target.

reply

The app decodes only what the action reply shape promises.

The request shape is:
For the exact request type, payload conversion table, reply type, cancellation behavior, and invalid examples, read Runtime Kit API.

Send JSON-like data

Use JSON-like payloads when your action reply shape is ordinary app data.

Send text

Runtime Kit encodes strings as bytes before sending.

Send bytes

If payload is already a Uint8Array, Runtime Kit sends those bytes.

Understand payload encoding

The target decides what those bytes mean. Your app and target should agree on a public contract, such as JSON in and JSON out.If a target needs JSON with a null value, send an object that contains the null field:

Decode the reply

The reply is always bytes because targets are not forced into one format.
For JSON replies:
For binary replies, keep the Uint8Array:

Cancel a request

Use an AbortController when the user leaves a screen, changes a search query, or cancels work.

Handle errors

Wrap user-triggered requests so the UI can recover.
An error means the public request did not complete. It does not mean the component should learn the private target implementation.

Before / after

Common mistakes

Using target names as storage addressesproduct.search is a callable target name. It is not a storage path.Parsing every reply the same wayThe reply is bytes. Decode according to the action reply shape. Do not assume every target returns JSON unless that target says it does.Calling private implementation code directlyIf a component imports the target implementation, the request boundary has been bypassed.Forgetting cancellationSearch boxes, typeahead, and long tasks should use an abort signal so stale work can stop.

Quick reference

With cancellation:
Decode JSON:

Now build the bigger version

Write the action reply shape before the button.
Then make the button use only that contract:
For binary work, keep the same shape. The target name stays public, the payload contract stays explicit, and the reply stays bytes:
Last modified on May 10, 2026