Explorer

html-ui.handle-api

description
(en) POST /api/<name> of the editable html-ui: calls the MCP tool html-ui.api-tool with the JSON body as its arguments and returns its text
type
Fn(language: String, config: @html-ui.config, path: String, body: String) -> @definy.service-io
expression
fn(language$990, config$3, path$0, body$1) =>
  let tool$4 = @html-ui.api-tool(name: @html-ui.segment(segments: @core.string-split(text: $0, separator: "/"), index: 2));
  match @core.and(left: $3.editable, right: @core.equal(left: $0, right: "/api/secret")) {
    true =>
      @html-ui.save-secret(language: $990, body: $1),
    false =>
      match @core.and(
          left: @core.and(left: $3.editable, right: @std.string-starts-with(value: $0, prefix: "/api/")),
          right: @core.not(value: @core.equal(left: $4, right: ""))
        ) {
        true =>
          @html-ui.rpc(
            config: $3,
            method: $4,
            request: $1,
            then: fn(response$2) =>
              @html-ui.text-response(status: $2.status, text: $2.text)
          ),
        false =>
          @html-ui.text-response(status: 404, text: "not found")
      }
  }
visibility
public
html-ui.handle-api (project html-ui, branch main, snapshot Daaw3vbJhY15cDW6JsA4JuXvffjj_qFyxoZQMUM8hvQ)
id: 9BCd4H-PxmCq63EaaiVMOAyFPIOEH2_UEsnARYqubVs
content hash: ZTje1eL00nj1fIJN12rBGZ0TzCaD10jVhRRhiSauu8g