Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose a simple friendlier GET API for retrieving contract state, eg. for use with curl. #904

Open
gogo2464 opened this issue Dec 5, 2023 · 7 comments
Labels
C-feature Category: New feature or request first-issue Good first issue to start contributing.

Comments

@gogo2464
Copy link
Contributor

gogo2464 commented Dec 5, 2023

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?

@sanity sanity added the C-feature Category: New feature or request label Dec 6, 2023
@sanity
Copy link
Collaborator

sanity commented Dec 6, 2023

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.

@iduartgomez iduartgomez added E-easy Experience needed to fix/implement: Easy / not much first-issue Good first issue to start contributing. E-medium Experience needed to fix/implement: Medium / intermediate and removed E-easy Experience needed to fix/implement: Easy / not much first-issue Good first issue to start contributing. labels Dec 7, 2023
@iduartgomez
Copy link
Collaborator

iduartgomez commented Dec 7, 2023

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.

@iduartgomez iduartgomez added first-issue Good first issue to start contributing. and removed E-medium Experience needed to fix/implement: Medium / intermediate labels Dec 7, 2023
@iduartgomez
Copy link
Collaborator

If you need any help while implementing feel free to just post them here and I'll help you moving as fast as possible.

@gogo2464
Copy link
Contributor Author

gogo2464 commented Jan 9, 2024

I have some ideas about how to expose contract state. I am also working on how to expose an API filtered by user inetrface.

@Julian-Dumitrascu
Copy link

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.

@gogo2464
Copy link
Contributor Author

gogo2464 commented Jan 9, 2024

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.

@Julian-Dumitrascu
Copy link

recorded

I've started this conversation to help anyone make such requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: New feature or request first-issue Good first issue to start contributing.
Projects
None yet
Development

No branches or pull requests

4 participants