Explorer

definy.request-json-of

description
The body of the request as a JSON object (an empty body is {})
type
Fn(request: @http.request) -> @definy.request-json
expression
fn(request$0) =>
  let text$1 = @std.bytes-to-string(bytes: $0.body);
  match @core.equal(left: @definy.string-trim(value: $1), right: "") {
    true =>
      #json<@definy.request-json>(#object<@definy.json>([])),
    false =>
      match @definy.parse-json(text: $1) {
        #ok(json$2) =>
          match $2 {
            #object(_) =>
              #json<@definy.request-json>($2),
            _ =>
              #invalid<@definy.request-json>("request body must be an object")
          },
        #error(message$3) =>
          #invalid<@definy.request-json>(@core.string-concat(left: "request body must be JSON: ", right: $3))
      }
  }
visibility
public
definy.request-json-of (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: 1IqDo5Tr96_lIsQ1iUIWsiLYN2okfTGzBGaFbadIHEA
content hash: u3mZuna91yt_-4gf3thFbQ55PFq3E2hjBGcZFgPjUh4