freenet-core
freenet-core copied to clipboard
expose a simple friendlier GET API for retrieving contract state, eg. for use with curl.
I would like to connect mobile and web apps to freenet. Could we create a way to interact directly to contracts, delegate and user interface directly from web or apps please?
We could also support puts using HTTP PUT, although the user would need to provide the contract WASM in addition to the updated state or delta.
A couple comments/caveats first.
There are some things are not keen to using regular HTTP requests like the subscribe and updates since the way it works it would require polling from the client side so that's gonna feel a bit awkward compared to the more natural websocket approach where we are essentially implementing a pub/sub model though it.
That said, I can see the value of this and ease of use if you want to do approach managing contracts in a more traditional style, like through a REST API.
The implementation should be done via adding new path handlers to the existing http gateway server handling the websocket connections. See crates/core/src/server/http_gateway.rs:as_router function.
We would add new route handlers under the /contract/api/<OPERATION> (so for example /contract/api/get). After that we can add support in the stdlib to support the API, since we will re-using the types defined through the common schemas and serializing/deserializing flatbuffers, need to make that friendlier to the user.
But we can break the task in 2 separate PR's so is easier to implement and review. So first do the necessary changes to the server. The server needs to handle the requests to the contract executor and then wait for an answer, since all that is running on it's own task/thread, you can check how this is done in the websocket implementation at crates/core/src/client_events/websocket.rs:websocket_interface .
The regular HTTP request one should be a simplier version of this, and we would need a separate handler for each operation (let's just start with get since that's relatively simple). I could get this done quickly but I will leave it open to implement to anybody who wants to help contributing so they get more familiar with how the whole application is setup.
P.S. Also must comment that curl can upgrade connections to use websockets, although it ain't the more natural/easiest to use thing, since this is what this initially spawned the request.
If you need any help while implementing feel free to just post them here and I'll help you moving as fast as possible.
I have some ideas about how to expose contract state. I am also working on how to expose an API filtered by user inetrface.
I have some ideas about how to expose contract state. I am also working on how to expose an API filtered by user inetrface.
Would you enjoy a public talk or a private talk about this? Either way, we can schedule a talk soon.
I have some ideas about how to expose contract state. I am also working on how to expose an API filtered by user inetrface.
Would you enjoy a public talk or a private talk about this? Either way, we can schedule a talk soon.
Yes I would love to enjoy a private talk. I also think a public dev documentation could benefit to the dev community. I just would not like to be recorded.