def http.web

ezmcp@0.1.0.0 · src/io.bend:62

import ezmcp@0.1.0.0/src/io.bend as Io
import Base
import emerging-ezjson@1.2.0.0/src/value.bend as Value
import emerging-ezhttp@0.21.0.0/src/http.bend as Http
import ezmcp@0.1.0.0/src/rpc.bend as Rpc
import ezmcp@0.1.0.0/src/server.bend as Server
import ezmcp@0.1.0.0/src/web.bend as Web

62# act on the transport's decision: reply now, or run the tool and reply
63# with its result, or run a batch's acts and reply with their replies
64def http.web(
65  ~C: Data,
66  ~run: C -> String -> Value.Json -> IO(Rpc.Out),
67  +ctx: C,
68  wid: Web.Web
69) -> IO(Http.Reply):
70  match wid:
71    case Web.Now{status, headers, body}:
72      IO.pure(Http.Reply, Http.Reply{status, headers, body})
73    case Web.Later{rev, id, name, args}:
74      IO.bind(Rpc.Out, Http.Reply, run(ctx, name, args),
75        out => IO.pure(Http.Reply, Web.reply(Web.ran(rev, id, out))))
76    case Web.Many{+rev, acts}:
77      IO.bind(List<&2, Maybe<&2, Value.Json>>, Http.Reply,
78        act.all(C, run, ctx, rev, acts),
79        rs => IO.pure(Http.Reply, Web.reply(Web.many(Server.batch.reply(rs)))))

Uses (15)

Used by (3)