~/bend-docscommunity

PROPOSED.bend source

PROPOSED.bend on the hub · documented module

# Route's laws, proposed (for the human to move into a LAWS.bend, reword or# drop): PROOF.bend proves them. An API means what serving it does; these say# that the ways of putting APIs together mean what they should, on every# request and every server.import Baseimport hhefesto-wire@1.0.0.0/Wire.bend as Wimport ./Route.bend as R# Nothing is choice's identity, on the left and on the right: an API offered# beside the one that answers nothing serves as the API alone.law alt_id_left:  for +a: R.rt.Api  for s: R.rt.Server(a)  for +req: W.wr.Req  {R.rt.serve(R.rt.Alt{R.rt.Nothing{}, a}, (Unit{}, s), req) == R.rt.serve(a, s, req) : IO(W.wr.Resp)}law alt_id_right:  for +a: R.rt.Api  for s: R.rt.Server(a)  for +req: W.wr.Req  {R.rt.serve(R.rt.Alt{a, R.rt.Nothing{}}, (s, Unit{}), req) == R.rt.serve(a, s, req) : IO(W.wr.Resp)}# Choice is associative: how alternatives are grouped does not change what# a request gets (the first to answer, or the first final error, or the# most telling miss), the servers grouped the same way.law alt_assoc:  for +a: R.rt.Api  for +b: R.rt.Api  for +c: R.rt.Api  for sa: R.rt.Server(a)  for sb: R.rt.Server(b)  for sc: R.rt.Server(c)  for +req: W.wr.Req  {R.rt.serve(R.rt.Alt{R.rt.Alt{a, b}, c}, ((sa, sb), sc), req) == R.rt.serve(R.rt.Alt{a, R.rt.Alt{b, c}}, (sa, (sb, sc)), req) : IO(W.wr.Resp)}# A literal segment distributes over a choice: "/p" in front of a choice is# the choice of the two with "/p" in front.law seg_dist:  for +p: String  for +a: R.rt.Api  for +b: R.rt.Api  for sa: R.rt.Server(a)  for sb: R.rt.Server(b)  for +req: W.wr.Req  {R.rt.serve(R.rt.Seg{p, R.rt.Alt{a, b}}, (sa, sb), req) == R.rt.serve(R.rt.Alt{R.rt.Seg{p, a}, R.rt.Seg{p, b}}, (sa, sb), req) : IO(W.wr.Resp)}# A text capture reads back what is printed for it.law text_round:  for v: String  {R.rt.parse(R.rt.TText{}, R.rt.print(R.rt.TText{}, v)) == Done{v} : Result<&2, &2, String, String>}