5b50279851
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.
55 lines
2.0 KiB
OCaml
55 lines
2.0 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 = Resto.MakeService(RestoJson.Encoding)
|
|
open Service
|
|
|
|
type meth = [ `GET | `POST | `DELETE | `PUT | `PATCH ]
|
|
module Arg = Arg
|
|
module Path = struct
|
|
type 'params t = (unit, 'params) Path.path
|
|
type 'params path = (unit, 'params) Path.path
|
|
let root = Path.root
|
|
let add_suffix = Path.add_suffix
|
|
let add_arg = Path.add_arg
|
|
let (/) = add_suffix
|
|
let (/:) = add_arg
|
|
let map = Path.map
|
|
end
|
|
module Query = Query
|
|
type ('meth, 'params, 'query, 'input, 'output, 'error) service =
|
|
('meth, unit, 'params, 'query, 'input, 'output, 'error) Service.t
|
|
let get_service = get_service
|
|
let post_service = post_service
|
|
let delete_service = delete_service
|
|
let put_service = put_service
|
|
let patch_service = patch_service
|
|
type 'input input = 'input Service.input =
|
|
| No_input : unit input
|
|
| Input : 'input Json_encoding.encoding -> 'input input
|
|
type 'input request = 'input Service.request = {
|
|
meth: meth ;
|
|
path: string list ;
|
|
query: (string * string) list ;
|
|
input: 'input input ;
|
|
}
|
|
let forge_request = forge_request
|
|
let query = query
|
|
let input_encoding = input_encoding
|
|
let output_encoding = output_encoding
|
|
let error_encoding = error_encoding
|
|
module Description = Resto.Description
|
|
type description_service =
|
|
([`GET], unit * string list, Description.request,
|
|
unit, Json_schema.schema Description.directory, unit) service
|
|
let description_service = description_service
|