Define a json protocol with session support #1732
Replies: 2 comments 7 replies
-
This is an interesting idea. My worry is that migrating from a client library implementing the proposed JSON protocol to a library that implements binary isn't going to be straightforward, because scalar types can't always be decoded in proper host language types. In a scenario when, say, C# has a popular edgedb library built with JSON protocol, there will be some of the features available in say edgedb-js wouldn't be possible to implement in the C# one. Since you and @tailhook are into Rust, I have a question: is it possible to design a sans-io Rust library implementing the protocol parser/flow and use it to create drivers for c++, .net, etc? The client library will need then to only implement basic scalar codecs and add an IO layer. |
Beta Was this translation helpful? Give feedback.
-
If we got this route I think we should make a JSON protocol on top of WebSockets, so we can also use it from the browser. And I think it's possible to find WebSockets library for any language nowadays. JSON is not great because of types, but we can probably allow switching protocol into binary on per-query basis, so one can start with JSON protocol and then gradually upgrade protocol implementation and application to use better protocol. Still not sure if it worth it. What language(s) do you have in mind? |
Beta Was this translation helpful? Give feedback.
-
Currently there are two ways to access EdgeDB via EdgeQL:
The binary protocol
Implementing it is complex and a significant amount of work. This limits the number of clients you can develop and makes it unlikely that outsiders implement their own client for their favourite language.
The http json protocol
This doesn't support sessions, authentication, transactions, etc. These limitations make it unusable outside demonstration contexts.
Enhancing it with session support is difficult, since the stateless nature of http makes it difficult to detect
Implementing clients for this is easy, in a language supporting json. I had written a proof-of-concept in C# in a couple of hours, but gave up when I realized its limitations.
I propose defining a json based protocol based on top of persistent tcp/tls connections.
I'd take inspiration from the json-lines format (one json value per line, prohibiting raw linebreaks inside the value), defining a line as a message. I'd keep the type of the message outside of the json object, so the type the json should be de-serialized to is known before parsing it.
For queries the request/response payload would look like the json objects the http API uses, so implementing it shouldn't be too much effort.
Beta Was this translation helpful? Give feedback.
All reactions