# Workstation HTTP integration

Connect authorized stores and use conditional requests to avoid overwriting another user's work.

## Connect existing services

`handleOFDHttpRequest` accepts a standard Fetch `Request`, mounted at `/ofd` by default. Provide the current caller's template library, draft store and optional queue. The host owns authentication, tenant isolation, persistence and auditing. Browser adapters such as `createOFDHttpDraftStore` can point at the same base URL.

### recipes/workstation.ts

```ts
import { handleOFDHttpRequest, type OFDHttpServices } from "@quirekit/ofd-editor/http";

/**
 * Installs the OFD routes behind the host's existing session and access policy.
 * @param servicesFor - Resolves services restricted to this caller and tenant.
 * @returns A Fetch handler mounted at /ofd/.
 */
export function workstationHandler(servicesFor: (request: Request) => Promise<OFDHttpServices | undefined>) {
  return async (request: Request): Promise<Response> => {
    const services = await servicesFor(request);
    if (!services) return new Response(null, { status: 403 });
    return handleOFDHttpRequest(request, services, "/ofd");
  };
}

```

<a href="/downloads/workstations.openapi.json" download="workstations.openapi.json">Download the workstation OpenAPI JSON</a>. The contract's `127.0.0.1:8998/ofd` server is the repository's synthetic local service. Use your deployment's own address. The public static demo offers local document operations.

## Generate an OFD from a versioned template

| Step | Request | Result |
| --- | --- | --- |
| Select a template | `GET /ofd/templates` | Choose the `id` and `revision` of a visible entry |
| Inspect fields | `GET /ofd/templates/{id}/fields` | Scalar fields, detail groups and a v3 example |
| Review input | `POST /ofd/templates/{id}/preflight` | Compare the submitted data with the target fields |
| Generate the file | `POST /ofd/templates/{id}/draft` | `201` and `application/ofd` bytes |
| Register a business draft | `PUT /ofd/drafts/{id}?name=report.ofd` | Persist OFD bytes and receive a business revision |

Send the same strong `If-Match` on the template fields, preflight and generation requests. For revision `1` the header is `If-Match: "1"`. Use `Content-Type: application/json` for fill data and `application/ofd` for storing file bytes. First registration uses `If-None-Match: *`. Subsequent writes use the strong ETag obtained when opening that draft.

## Update a saved draft

Read `GET /ofd/drafts/{id}` and use its revision with `POST /ofd/drafts/{id}/preflight` and `POST /ofd/drafts/{id}/fill`. A missing required precondition returns `428`. A stale revision returns `412`. Reload and review against the latest edition before confirming. Bulk operations use `batch-preflight` and `batch-drafts` and return results per item. [One fill-data contract](/en/integration/data)
