UNPKG

ketting

Version:

Opinionated HATEOAS / Rest client.

32 lines 1.02 kB
import { BaseState } from './base-state.js'; import { parseLink } from '../http/util.js'; import { parseHtml } from '#html'; import { resolve } from '../util/uri.js'; /** * Turns a HTTP response into a HtmlState */ export const factory = async (client, uri, response) => { const body = await response.text(); const links = parseLink(uri, response.headers.get('Link')); const htmlResult = parseHtml(uri, body); links.add(...htmlResult.links); return new BaseState({ client, uri, data: body, headers: response.headers, links, actions: htmlResult.forms.map(form => formToAction(uri, form)), }); }; function formToAction(context, form) { return { uri: 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