You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
method field contains information about API method that request is calling.
params field contains actual data needed for the method of API, it can have any structure: list, object, raw value etc.
As for now we are using Http4s for it and we have to do dynamic dispatch on field method and then decode params as desired object:
caseclassJRPCRequest[A](id: String,
jsonrpc: String,
method: String,
params: A)
defhandleReq(req: Request[F]):F[Response[F]] = getMethodFromRequest(req) match {
case"foo"=> req.as[JRPCRequest[Foo]] >>= (...) some foo handler
case"bar"=> req.as[JRPCRequest[Bar]] >>= (...) some bar handler
case _ => ... //bad request here
}
where getMethodFromRequest gets method field from JSON.
All this boilerplate code doesn't look very good and is a pain to support, and I'm not even talking about documentation like swagger etc.
I've tried using tapir somehow by creating two endpoints:
But this didn't work, only Int endpoint have been working while the other's response was "Error: Bad Request"
So is there any possibility to add JSON RPC support directly into tapir?
I would like to implement it but I need some advices on where to start or what are the best options.
Anyway thank you guys for the great library!
The text was updated successfully, but these errors were encountered:
As I understand the differentiator between requests is the method field. And you have a single endpoint, which has the server logic dependent on that method?
I think I would start by defining this single endpoint, deserialising the body into a JRPCRequest[Json] (assuming you are using circe). Then, in the server logic, you could dynamically decide which server logic method to run, depending on the method value.
I don't think open api will be of much help. From OpenAPI's viewpoint (and tapir's currently as well), you have a single endpoint, but with complex and dynamic server logic. You could probably document the input/output, though, as a schema with multiple alternatives.
Hello!
In my organization we are using tapir and it feels like a very good tool.
Nevertheless we are also heavily using JSON RPC protocol and tapir doesn't help us at all.
Here is the example:
method
field contains information about API method that request is calling.params
field contains actual data needed for the method of API, it can have any structure: list, object, raw value etc.As for now we are using Http4s for it and we have to do dynamic dispatch on field
method
and then decodeparams
as desired object:where
getMethodFromRequest
getsmethod
field from JSON.All this boilerplate code doesn't look very good and is a pain to support, and I'm not even talking about documentation like swagger etc.
I've tried using tapir somehow by creating two endpoints:
But this didn't work, only
Int
endpoint have been working while the other's response was "Error: Bad Request"So is there any possibility to add JSON RPC support directly into tapir?
I would like to implement it but I need some advices on where to start or what are the best options.
Anyway thank you guys for the great library!
The text was updated successfully, but these errors were encountered: