> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# REST feed source

> Mount a bounded JSON feed on your app.

Mount `@bijectionhq/app-rest` for one collection on a fixed HTTPS GET
path. Records, cursor positions and task results live under the `data` label
you pass to the mount.

## Mount and bind

`rest({ data, receivers })` returns the app to place at a path of your tree.
Bind the collection with one of the package's binders, declare each credential
with `secret()`, and place them beside the mount. Only `receivers.provider` is
required; a feature whose receiver you did not pass refuses `ReceiverUnbound`.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import rest, { restEndpoint } from "@bijectionhq/app-rest";

const items = label();
const clientSecret = secret();
const refreshToken = secret();
const provider = restEndpoint("https://catalog.example", "/v1/items", {
  kind: "oauth2",
  tokenEndpoint: "https://catalog.example/oauth/token",
  clientId: "catalog-reader",
  clientSecret,
  refreshToken,
}, items);

export default app({ items, clientSecret, refreshToken, provider, catalog: rest({ data: items, receivers: { provider } }) });
```

The mount declares its `operator` role, which clears `data`. The operator runs
the mount's clocks and is the only role its functions allow:
`catalog.source.*`, `catalog.records.*`, `catalog.schema.*`, `catalog.files.*`,
`catalog.reports.*` and `catalog.writes.*`. Set each credential, grant the role,
and initialize the source with a profile:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection secret set clientSecret
bijection secret set refreshToken
bijection mutate catalog.source.initialize profile:="$(jq -c .profile profile.json)"
```

`catalog.operator` is granted from code: `ctx.grant(catalog.operator, { to, under })` in one of your
mutations ([Grants](https://docs.bijection.com/access/grants.md)).

```json profile.json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "profile": {
    "mode": "declared",
    "selection": { "provider": "rest", "resource": "/v1/items", "origin": "https://catalog.example", "path": "/v1/items", "start": null },
    "limit": 50,
    "keys": [],
    "fields": [
      { "name": "id", "path": ["id"], "type": "string", "nullable": null, "optional": null },
      { "name": "name", "path": ["title"], "type": "string", "nullable": true, "optional": null }
    ],
    "json": {
      "page": { "records": ["items"], "key": ["id"], "limitParameter": "limit", "query": null },
      "deletion": { "kind": "boolean", "field": ["deleted"] },
      "cursor": { "kind": "checkpoint", "parameter": "after", "field": ["checkpoint"], "more": ["hasMore"] }
    },
    "schemaRevision": null
  }
}
```

Repeating initialization with the same profile is safe. The receiver
exchanges and refreshes OAuth2 tokens. An endpoint can also use bearer
or header auth, or be unauthenticated. Credentials reach the provider only
through the receiver's `auth`; keep them out of profiles and arguments.

Every binder takes the `data` label as its last argument, and the receiver
answers under it. For protected data, declare a concrete label and pass it to
both the binder and the mount. The host charges clock and send capacity at
that label.

The provider guides give the fixed path and a `profile` for each native
mode. For those modes, set `mode: "provider"`, use the catalog's exact mode
as `provider`, and bind the collection with
`providerEndpoint(mode, origin, path, auth, data)`. A guide lists the
profile members its mode uses; every other member is `null`. Use one mount
per mode and resource. For HTTP Basic, use header authentication with
`name: "Authorization"` and `prefix: "Basic "`, and set only the
Base64-encoded credential value.

### Protected SaaS mounts

Declare a label appropriate to the data, such as `label()`. Pass it to
`providerEndpoint` and to the mount as `data`. Grant the mount's `operator`
role only to principals who may read that data: the operator reads the
records. The source stores its observations and positions under `data`.
Provider responses reach the continuation under the same label and may
contain more provider fields than the listed record projection. A mode that
requires a protected label refuses `ProtectedLabelRequired` under the public
label.

Pass the receiver as `receivers.provider` and set each of its credentials.
Initialize with the exact `provider` mode and the limit shown in its guide.
Use one mount per tenant or feed. Each page must fit in 36 KiB and the
configured row limit. Oversized or invalid pages leave the last landed
position intact. Traversals commit one page at a time. An ordinary
observation sweep starts again after its terminal page and keeps rows that
disappear from later responses.

### Multiple sealed credentials

For a fixed HTTPS receiver that needs several credentials, declare
`auth: { kind: "multiSecret", bindings: [...] }` with two to eight
separate `secret()` declarations. Each binding uses `kind: "header"` and
a header name, with an optional prefix, or `kind: "query"` and a query
parameter name. Set each value with `bijection secret set`. The host owns
those names and adds the values immediately before dispatch. Keep
credentials out of source profiles and request arguments.

A fixed HTTPS POST can also use `multiSecret` with one or more
`jsonBody` bindings. Give each binding its own secret and a
`fieldPath`, such as `["access_token"]` or
`["getSettledBatchListRequest", "merchantAuthentication"]`. The request
must supply any parent objects and leave the credential fields absent.
The host opens each seal and inserts text, or parsed JSON when
`json: true`. Seal separate root fields such as `secret` and
`access_token` independently.

## Feed contracts

| Contract | Declaration |
| - | - |
| Page | Supply the JSON path to the record array and each record's stable key. Use an empty records path for a top-level array. Keys are non-empty strings or safe integers and appear as text in the API. Set a ceiling of 1–100 records. Use ordinary non-secret static query parameters and, optionally, a provider limit parameter. |
| Projection | Select 1–32 named output fields, with paths and declared types. Mark nullable and optional fields explicitly. Only projected fields are published. Decimal values retain exact text. |
| Deletion | Choose `none` or a required boolean marker. A true marker deletes the current row for the same key. Missing rows leave prior observations in place. |
| Cursor | Choose `single` for a one-page poll, `restart` for a walk that starts over once its next token is absent, or `checkpoint` for a token retained across polls. A checkpoint page always supplies a token and a boolean saying whether more pages are currently ready. A token is sent only as a query parameter on the bound path. |

The app accepts at most 36 KiB of UTF-8 response data per page and uses the
bundled parser to bound records, fields and nesting while preserving exact
text for decimals and integers outside the safe range. It commits keyed
upserts and deletions with the page position. A traversal yields after 16
pages and reports a failed page if its continuation makes no progress or
would exceed 4,096 pages. An HTTP 410 for a retained position records a gap
and stops the source.

Use `records.get` with the provider key or page `records.list`.
`records.list({ cursor })` returns `{ facts, next }`; pass `next` as the
following call's `cursor`, and start with `null`. A mount under a labelled
`data` is [protected](https://docs.bijection.com/database/protected-tables.md): its store keeps only a
token of each key, so `records.list`, `relationships.list` and
`occurrences.list` page in row order. A public mount pages records in key
order. The mount's `orders` release keeps only schema generations, write
states and due times, and report run keys and row ordinals public, so its
generation sweep, write queue and report rows walk in order.

The mounted clock starts due reads and recovers stalled runs. A manual
`poll` marks the feed due for its next clock turn. Use the revision shown
by `source.health` when calling `poll`, `pause` or `resume`; a stale
revision refuses `RevisionMoved`. Pass both the displayed revision and gap instant to `source.reset`
after reviewing a lost position. Reset starts at the configured baseline
and preserves published rows. For a different collection, account or
provider incarnation, install a new mount so its cursor and rows start fresh.
The minute cadence and per-page commits provide current observations only.
Deploying this app requires the bundled parser module.

## Discover and approve a provider schema

For Airtable, Salesforce, HubSpot, Pipedrive, Zoho CRM, Close, Attio, NetSuite,
Dataverse, Zendesk or Jira, use the provider guide's `selection` with
`declaredResourceEndpoint(selection, auth, data)`. Pass it as
`receivers.resource` and use a protected label for the receiver and the
mount. The one receiver carries the fixed collection and metadata
routes under the same HTTPS origin and sealed credential.

1. Call `schema.discover({ selection, revision: null })` before first
   initialization. For an existing source, use the current source revision.
2. Call `schema.get()` until the proposal is ready. Review the provider
   fields, normalized types, key, paging and deletion contract. The receiver
   stages each complete metadata response in sealed 512 KiB parts, up to 2 MiB
   per response. The app checks the size and digest, parses the staged JSON
   and retires the parts. A review accepts up to 512 supported fields across
   at most 32 pages, with a 15-minute discovery deadline.
3. Call `schema.approve({ proposal, fingerprint, revision, fields, limit })`
   with the exact proposal, fingerprint and discovery basis
   (`reviewedAtRevision`), 1–32 of its field names and a 1–100 row page limit.
   Approval starts the initial source. Later approvals that change the
   schema or selected fields start a new record generation and baseline.
   The previous generation stops appearing in record reads.
4. While the source is active, the app schedules a daily metadata refresh.
   A changed schema pauses acquisition and exposes a new proposal.
   Approve the revision, then use its returned source revision with
   `source.resume`. Use `source.health` and `source.reset` first if the
   source has a continuity gap. An unchanged schema keeps its active
   projection and cursor.

A revision admits the supported names and value representations returned by
the provider. Unsupported types and fields outside the reviewed projection
stay out of published records. A value that violates the projection fails its
page without moving the committed position. Use a new mount to change the
account, object or collection path.

## Create and update records

Declare a separate write credential and writer. For a generic REST API, bind
one create path, one update collection prefix and the update method. The
writer appends exactly one validated record ID under that prefix.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import rest, { restEndpoint, restWriter } from "@bijectionhq/app-rest";

const writeToken = secret();
const writer = restWriter("https://catalog.example", {
  create: "/v1/items", update: "/v1/items", method: "PATCH",
}, { kind: "bearer", secret: writeToken }, items);
// in the tree: { writeToken, writer, catalog: rest({ data: items, receivers: { provider, writers: { rest: writer } } }) }
```

`receivers.writers` holds one writer per write mode; the generic mode is
`rest`. Bind the writer under the same label as the mount. The operator calls
`catalog.writes.submit` and `catalog.writes.get`. A pull-only mount passes no
writers.

Call `writes.submit` with a command `key`, `mode: "rest"` and
`command: { action: "create", payload }` or
`command: { action: "update", id, payload }`. The payload is one JSON
object encoded as text, up to 24 KiB. The command key is 1–100 ASCII letters,
digits, dots, dashes or underscores. A repeated key with the same exact
inputs answers `replayed`. Changing the mode, action, ID or payload under that
key refuses `KeyReused`.

The mount queues under `data` and its clock submits one task per command
key, `once` on that key. Work that waits in the queue for five minutes
expires. The clock submits at most one write per ten-second turn. Use
`writes.get({ key })` for the labelled evidence. Read polling and cursor
advancement are independent of write evidence.

A generic 200, 201 or 204 acknowledges the request at the installed
endpoint. For a JSON response, the app can retain an `id` that fits its key
contract. A 202 or a redirect provides insufficient application evidence.
`httpError` records an HTTP status the endpoint returned. `unexpected`
records a reply without the mode's expected evidence. `unknown` records a task
that settled `Unknown`. A write may have applied when either the reply
or its expected evidence is unavailable.

Each command has one send and one final result. Resolve an `Unknown`
result against the provider's records before acting on it.

## Native provider writes

Each provider guide lists its exact mode, origin, resource scope, credential
and reply evidence. Bind the writer with `providerWriter(mode, options, label)`
and pass it in `receivers.writers` under its own mode. Bind the writer and the
mount under the same `data` label. Use a credential with write permission for
the specific resource.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import rest, { restEndpoint, providerWriter } from "@bijectionhq/app-rest";

const tasks = label();
const readToken = secret();
const writeToken = secret();
const provider = restEndpoint("https://app.asana.com", "/api/1.0/tasks",
  { kind: "bearer", secret: readToken }, tasks);
const writer = providerWriter("asana.tasks.create-update-delete", {
  endpoint: "https://app.asana.com",
  auth: { kind: "bearer", secret: writeToken },
}, tasks);

export default app({
  tasks,
  readToken,
  writeToken,
  provider,
  writer,
  asana: rest({ data: tasks, receivers: { provider, writers: { "asana.tasks.create-update-delete": writer } } }),
});
```

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection mutate asana.writes.submit '{"key": "task-81", "mode": "asana.tasks.create-update-delete", "command": {"action": "update", "id": "1204", "payload": "{\"completed\":true}"}}'
```

Use one command key for one exact mode, action, record ID and payload.
Create and update take one JSON object encoded as text, up to 24 KiB.
Delete takes only an exact record ID. Replaying the key answers the queued
decision. `writes.get({ key })` reports pending, sending or settled evidence
with a provider HTTP status and record ID where the mode can establish them.
The write has no cursor and updates no observed row. A later pull follows
its regular cursor and deletion rules. An unexpected or missing reply can
leave the provider effect unresolved.

### Typed commands

Use the exact mode and command shape in the provider's guide. Bind the reviewed
writer to the same protected `data` label as the mount; typed writes refuse
`ProtectedLabelRequired` under the public label. Only the mount's operator
calls `writes.submit` and `writes.get`.
The key binds the entire command. Each provider follow-up takes its own
ordered task under that key and the writer's receiver contract.

`writes.get({ key })` returns `state`, the last HTTP `status`, and the
provider-specific `record` and `detail`. The `job` field identifies an
acknowledged background job and `outcomes` holds any per-record evidence.
The app bounds the initial queue to five minutes and any follow-up to
30 minutes. A send that settles `Unknown` is never resent.
Write commands have no read cursor and never move a source position.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.