UNPKG

ketting

Version:

Opiniated HATEAOS / Rest client.

36 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.factory = void 0; const base_state_1 = require("./base-state"); const util_1 = require("../http/util"); const html_1 = require("../util/html"); const uri_1 = require("../util/uri"); /** * Turns a HTTP response into a HtmlState */ const factory = async (client, uri, response) => { const body = await response.text(); const links = (0, util_1.parseLink)(uri, response.headers.get('Link')); const htmlResult = (0, html_1.parseHtml)(uri, body); links.add(...htmlResult.links); return new base_state_1.BaseState({ client, uri, data: body, headers: response.headers, links, actions: htmlResult.forms.map(form => formToAction(uri, form)), }); }; exports.factory = factory; function formToAction(context, form) { return { uri: (0, uri_1.resolve)(context, form.action), name: form.rel || form.id || '', method: form.method || 'GET', contentType: form.enctype || 'application/x-www-form-urlencoded', // Fields are not yet supported :( fields: [], }; } //# sourceMappingURL=html.js.map