Diff text
Try it interactively →POST /api/diff-textDiff two text inputs at line, word, or character granularity. Returns the unified diff plus per-segment add/remove arrays for custom rendering.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| before* | string | — | Original (pre-change) text. |
| after* | string | — | Modified (post-change) text. |
| mode | enum (unified | split | stats) | "unified" | Output flavor. |
| granularity | enum (line | word | char) | "line" | Granularity for split/stats; ignored for unified. |
| context | number (0…100) | 3 | Lines of unchanged context per hunk (unified only). |
Response
Modes: json, text. Cache: yes (24h TTL).
Code samples
Built from the small example.
curl -X POST https://api.xtract.bot/api/diff-text \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
-H "X-Api-Key: $XTRACT_API_KEY" \
-d '{
"before": "alpha\nbeta\ngamma\n",
"after": "alpha\nBETA\ngamma\n",
"mode": "unified",
"context": 3
}'