Add a local client
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 singlecall
method instead, as opposed to Cohttp_lwt.S.Client. - It introduces Local_client.Make that creates an instance of
Client.CLIENT
from (mainly) aunit Directory.t
. - To implement
Local_client
, the server's function callback was split into multiple functions, that are now used both fromserver.ml
andlocal_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 ofClient.CLIENT
from an instance ofCohttp_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
- I wrote tests: local_client_test.ml
- I've also adapted the
mockup-fake-baking
branch on my clone: smelc/mockup-fake-baking so that it uses this MR. It works: tests pass.
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 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