RPC: add answer functions with HTTP code argument to RPC interface.
This commit is contained in:
parent
cc44053229
commit
c6c81345a8
@ -98,7 +98,15 @@ module Description = struct
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Answer = RestoDirectory.Answer
|
module Answer = struct
|
||||||
|
|
||||||
|
include RestoDirectory.Answer
|
||||||
|
|
||||||
|
let answer ?(code = 200) json = { code; body = Single json }
|
||||||
|
let return ?code json = Lwt.return (answer ?code json)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
type step =
|
type step =
|
||||||
| Static of string
|
| Static of string
|
||||||
|
@ -184,7 +184,8 @@ module Answer : sig
|
|||||||
}
|
}
|
||||||
|
|
||||||
val ok: 'a -> 'a answer
|
val ok: 'a -> 'a answer
|
||||||
val return: 'a -> 'a answer Lwt.t
|
val answer: ?code:int -> 'a -> 'a answer
|
||||||
|
val return: ?code:int -> 'a -> 'a answer Lwt.t
|
||||||
val return_stream: 'a stream -> 'a answer Lwt.t
|
val return_stream: 'a stream -> 'a answer Lwt.t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -698,6 +698,17 @@ module Encoding = struct
|
|||||||
`Variable in
|
`Variable in
|
||||||
make @@ Mu (kind, name, self)
|
make @@ Mu (kind, name, self)
|
||||||
|
|
||||||
|
let result ok_enc error_enc =
|
||||||
|
union
|
||||||
|
~tag_size:`Uint8
|
||||||
|
[ case ~tag:1 ok_enc
|
||||||
|
(function Ok x -> Some x | Error _ -> None)
|
||||||
|
(fun x -> Ok x) ;
|
||||||
|
case ~tag:0 error_enc
|
||||||
|
(function Ok _ -> None | Error x -> Some x)
|
||||||
|
(fun x -> Error x) ;
|
||||||
|
]
|
||||||
|
|
||||||
let assoc enc =
|
let assoc enc =
|
||||||
let json = Json_encoding.assoc (Json.get_json enc) in
|
let json = Json_encoding.assoc (Json.get_json enc) in
|
||||||
let binary = list (tup2 string enc) in
|
let binary = list (tup2 string enc) in
|
||||||
|
@ -47,6 +47,7 @@ val string : string encoding
|
|||||||
val bytes : MBytes.t encoding
|
val bytes : MBytes.t encoding
|
||||||
val float : float encoding
|
val float : float encoding
|
||||||
val option : 'a encoding -> 'a option encoding
|
val option : 'a encoding -> 'a option encoding
|
||||||
|
val result : 'a encoding -> 'b encoding -> ('a, 'b) result encoding
|
||||||
val string_enum : (string * 'a) list -> 'a encoding
|
val string_enum : (string * 'a) list -> 'a encoding
|
||||||
|
|
||||||
module Fixed : sig
|
module Fixed : sig
|
||||||
|
@ -98,7 +98,8 @@ module Answer : sig
|
|||||||
}
|
}
|
||||||
|
|
||||||
val ok: 'a -> 'a answer
|
val ok: 'a -> 'a answer
|
||||||
val return: 'a -> 'a answer Lwt.t
|
val answer: ?code:int -> 'a -> 'a answer
|
||||||
|
val return: ?code:int -> 'a -> 'a answer Lwt.t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user