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

Can I REST over libp2p Connection? #181

Closed
hubertokf opened this issue Mar 29, 2018 · 3 comments
Closed

Can I REST over libp2p Connection? #181

hubertokf opened this issue Mar 29, 2018 · 3 comments
Labels
kind/support A question or request for support status/deferred Conscious decision to pause or backlog

Comments

@hubertokf
Copy link

I dont know if i can ask this here, but here it go.

I want to make an API with js-libp2p. I know that I can handle a protocol simply using handle function, but it do not give responses. For example: If i make a request to /api/resources/ i want to get a list of resources (ok, i do have procedures to get those resources from database e.g ). I just want to give a json (object) response.

Is there a way to do that?

If its not possible, i was planning to make a kind of handshake to deal with communications between a pair of peers.

@dryajov
Copy link
Member

dryajov commented Mar 30, 2018

Hrm... no. If I understand your question correctly you want to use protocol identifiers as RPC endpoints? In that case, that's not the correct usage. Even tho it might look like an endpoint name, it's not that, /api/resource is a multistream protocol name identifier, using it as some sort of RPC endpoint would not be the correct thing to do.

As for returning a JSON or any other data from your handler, you can but it has to be piped to the provided connection stream.

Take a look here https://github.com/libp2p/js-libp2p/blob/master/examples/echo/src/listener.js or here https://github.com/libp2p/js-libp2p/blob/master/examples/chat/src/listener.js for an example of a handle method implementation.

Note that we use http://caolan.github.io/async/docs.html and https://pull-stream.github.io/ through the codebase.

@hubertokf
Copy link
Author

RPC was the keyword!

Apologies about the delay. When i read you talking about RPC, i realized that it is what I need. So I found libp2p-rpc.

Thank you very much about the tip 👍

@daviddias daviddias added the status/deferred Conscious decision to pause or backlog label May 30, 2018
@daviddias daviddias changed the title [Question] Can i handle a Rest protocol? Can I REST over libp2p Connection? Jun 4, 2018
@daviddias daviddias added the kind/support A question or request for support label Jun 4, 2018
@daviddias
Copy link
Member

Great find! https://github.com/beingmohit/libp2p-rpc \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support A question or request for support status/deferred Conscious decision to pause or backlog
Projects
None yet
Development

No branches or pull requests

4 participants