Skip to content

Add a local client

Clément Hurlin requested to merge smelc/resto:smelc-local-client into master

This MR adds a local client, i.e. a client that honors requests without delegating them to a server. This local client was initially coded for tezos-client's mockup mode that performs RPC requests locally instead of delegating them to a node. This MR upstreams tezos' code (which is on branch richard.bonichon/mockup-fake-baking for the moment) to resto.

Changes

Here are the changes dones by this MR:

  • It weakens functor Client.Make so that it requires an instance of Client.CLIENT instead of an instance of Cohttp_lwt.S.Client. Client.CLIENT has a single call method instead, as opposed to Cohttp_lwt.S.Client.
  • It introduces Local_client.Make that creates an instance of Client.CLIENT from (mainly) a unit Directory.t.
  • To implement Local_client, the server's function callback was split into multiple functions, that are now used both from server.ml and local_client.ml. callback went down from 250 lines to 104 lines. Code sharing is done via module Server.Internal.
  • To ease transitioning to Client.Make's new API, the functor OfCohttp is introduced. It creates an instance of Client.CLIENT from an instance of Cohttp_lwt.S.Client.

Adoption

Adapting existing code to this MR is a matter of changing slightly the calls to Client.Make and Server.Make. See the corresponding tezos commit for an example of adoption on tezos.

Tests

Failing CI

The CI is failing because I did not succeed in adapting .gitlab-ci.yml. I hope the kind reviewers will provide assistance on this topic The issue is that I shared code in test/ by introducing the library resto-shared-test but this breaks installation of dependencies 🤦🏽

Timeline

Now that Tezos' mockup fake baking has been merged, this MR is important to be merged; because it'll make possible to remove the corresponding code from Tezos (the fake baking MR kinda brought this code to Tezos, but at the Tezos-level (less generic)).

Also it makes sense to merge this MR before others, because it conflicts a lot with others. Leaving this MR dangling will mean every rebasing will be hard.

Reviewers

Suggested reviewers: @raphael-proust @abate

Edited by Clément Hurlin

Merge request reports