ligo/vendors/ocplib-resto/test/services.ml
Grégoire Henry 5b50279851 Import new version of vendors/ocplib-resto
The new version of ocplib-resto :

- uses jbuilder ;
- is functorized over `Json_encoding` rather than `Json_repr` ;
- handles query parameters ;
- handles HTTP methods (GET, POST, DELETE, PUT, PATCH) ;
- replaces `custom_service` by a more generic trailer argument ;
- replaces generic answer `(code, body)` by a more ad-hoc sum type
  (allowing distinct encoding for success and error) ;
- includes a minimal HTTP-server based on Cohttp
  (includings CORS and media type negotiation).
- adds a function `Directory.transparent_lookup` to lookup/call
  a service handler without serializing the various parameters
  (path, query, request body).

As a first consequences in Tezos, this patch allows binary
communication between the client and the node.

This patch tries to be minimal inside the tezos source code and
therefore it introduces a minimal compatibility layer in
`RPC.ml`. This code should be removed as soon as possible.
2017-12-04 15:51:59 +01:00

79 lines
2.4 KiB
OCaml

(**************************************************************************)
(* ocplib-resto *)
(* Copyright (C) 2016, OCamlPro. *)
(* *)
(* All rights reserved. This file is distributed under the terms *)
(* of the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
open Resto
module Service = MakeService(RestoJson.Encoding)
open Service
(** Shared part *)
let repeat_service =
post_service
~query:Query.empty
~input:Json_encoding.any_ezjson_value
~output:Json_encoding.any_ezjson_value
~error:Json_encoding.empty
Path.(root / "foo" /: Arg.int / "repeat")
let add_service =
post_service
~query:Query.empty
~input:Json_encoding.int
~output:Json_encoding.int
~error:Json_encoding.empty
Path.(root / "foo" /: Arg.int / "add")
let alternate_add_service =
get_service
~query:Query.empty
~output:Json_encoding.float
~error:Json_encoding.empty
Path.(root / "bar" /: Arg.int /: Arg.float / "add")
let alternate_add_service' =
post_service
~query:Query.empty
~input:Json_encoding.null
~output:Json_encoding.int
~error:Json_encoding.empty
Path.(map
(fun (((),i),f) -> (i,int_of_float f))
(fun (i,f) -> (((),i),float_of_int f))
(root / "bar" /: Arg.int /: Arg.float / "add"))
let minus_service =
post_service
~query:Query.empty
~input:Json_encoding.null
~output:Json_encoding.float
~error:Json_encoding.empty
Path.(open_root /: Arg.int / "minus")
let describe_service =
description_service Path.(root / "describe")
let dummy_service =
post_service
~query:Query.empty
~input:Json_encoding.null
~output:Json_encoding.null
~error:Json_encoding.empty
Path.(root / "a" / "path" / "long" / "enough" /
"for" / "<hov>" / "to" / "trigger"
/: Arg.float /: Arg.float /: Arg.float /: Arg.float
/: Arg.float /: Arg.float /: Arg.float)
let prefix_dir1 = Path.(root / "tartine" /: Arg.float / "chaussure")
(** Client only *)
let real_minus_service1 = Service.prefix prefix_dir1 minus_service