fn(remote$0, method$1, request$2, then$3) =>
#handle<@definy.service-io>({
request: @http.request-of-url(
method: "POST",
url: @std.string-join(items: [$0, "/definy.v1.EventService/", $1], separator: ""),
headers: [{name: "Content-Type", value: "application/json"}],
body: @core.string-to-bytes(value: @definy.json-to-string(value: $2))
),
secret_headers: [],
then: fn(result$4) =>
match $4 {
#error(error$5) =>
$3(
result: #error(@std.string-join(items: ["Could not reach ", $0, ": ", @http.error-text(error: $5)], separator: ""))
),
#ok(response$6) =>
let text$7 = @http.body-text(response: $6);
match @core.equal(left: $6.status, right: 200) {
true =>
match @definy.parse-json(text: $7) {
#ok(json$9) =>
$3(result: #ok($9)),
#error(message$10) =>
$3(
result: #error(@std.string-join(items: [$1, " returned a body that is not JSON: ", $10], separator: ""))
)
},
false =>
$3(
result: #error(@std.string-join(
items: [$1, " failed (status ", @std.number-to-string(value: $6.status), "): ", $7],
separator: ""
))
)
}
}
})