function printBody
printBody(
received: Response,
palette: Theme,
limit: number
): string

The body, as much of it as was asked for.

JSON is re-indented before it is printed — an API that answers in one 8KB line is answering a machine, and this is not one. It is then run through the same highlighter the prompt uses, because JSON is JavaScript's own notation and the colours already mean the right things.

A body that is not text is never printed, only described. A terminal handed a PNG beeps, loses its cursor, and sometimes changes its own character set.

limit of Infinity is the whole thing, which is what .request … body asks for.

import { printBody } from './print-request.ts';

const plain = { painter: () => (text: string) => text };
const json = { status: 200, statusText: 'OK', headers: new Map([['content-type',
  'application/json']]), body: '{"a":1}', bytes: 7, bodyTruncated: false, binary: false };
printBody(json, plain, Infinity); // '{\n  "a": 1\n}'

Parameters

received: Response
palette: Theme
limit: number

Return Type

string

Usage

import { printBody } from "lib/commands/repl/print-request.ts";