Reconstruct Project Log


#1

Based on the feedback from the RFC I opened a few weeks ago, I’ve started experimenting on different approaches to a bs-express successor. The current state of the project can be found here: https://github.com/ncthbrt/reconstruct.

The idea is to combine request and response into a single httpContext type and make operations on this type be asynchronous using Repromises. Combining request and responses allows for a more composable API, which has been a pain point for real world usage at $CURRENT_JOB. Using repromise allows the API to be cross platform and is likely going to be future proof.

To make this more user friendly, a few judicious PPXes have been added for things like routing and monadic binding. I’ve largely been focusing on these PPXes and some other user facing stuff, as this has the most uncertainty and will drive requirements on the back. (i.e. Current state of the project is a possibly prettyish thing that compiles, but lots of integration work still remains)

Here is an example of how a typical endpoint looks like:

[%route.post "/users/userId:string/articles?offset:int=?&limit:uint=?"](
      (~userId, ~offset=0, ~limit=10) => {
          let%mesh articleText = Reconstruct.Request.bodyText;
          print_endline("Article submitted for user " ++ userId ++ ". Contents follow: " ++ articleText);
          Reconstruct.Machine.handled;
      }
);

The goal is to be able to offer an isomorphic api for both native and node compilation targets.

Will be posting progress here as I go along. If anyone is keen to step in and help, particularly on the native side (which is definitely my weak point), I’d be delighted.

Also any suggestions for the name of the bind (let%mesh) operator? Don’t want to use a name which has already been taken up.


#2

Having no experience with the library, everything here looks intuitive to me, except let%mesh. I must be misunderstanding what the mesh connotes. Is it like a bunch of variables can be assigned at once (forming a “mesh”?) Or that somehow they “mesh in” with … something else?


#3
let%mesh articleText = Reconstruct.Request.bodyText;

is rewritten to:

Reconstruct.Request.bodyText(articleText => {... });

Which is an expression which evaluates to type Machine.t and takes in a function takes in a string and returns another Machine.
I called it that for want of a better name. let%mesh because it is basically meshing two “machines” together.
Bind may be more appropriate, but worried that is taken. Could perhaps use let%recon.bind instead?