Possible to Make a P2PHTTP Request from Browser?

As the title says, I’m wondering if it’s possible to make a p2phttp request from the browser to a server running a libp2p node that uses this library? GitHub - libp2p/go-libp2p-http: HTTP on top of libp2p

To be clear this is not in relation to WebTransport, as that did come up a number of times while I was searching around.

This library is implemented in Go and browsers use JS, but in the “Usage” example of the github repo it shows that the client simply needs to pass a transport value to the “Transport” configuration variable of the http.Client{} and from there can make any requests it wants.

Looking at the Axios documentation for making HTTP requests from the browser it has a similar key name in the request configuration: axios - npm

In the p2phttp usage example that transport which is passed to the http client config was created using p2phttp.NewTransport(clientHost).

I’d like to try a similar thing with Axios as to what’s shown in this example but I’m not sure if it’s easy create that transport object in JS yet. Is it just a matter of patience before js-libp2p gets its own js-p2phttp library? Maybe this did have to do with WebTransport being integrated first so that a browser based node could be a first class node?

For my use case I can definitely stick with ordinary TLS, but ultimately I’d like to get away from having to rely on a certificate authority to provide secure http endpoints. For instance I’d like to set api.somename.eth (an ENS) to an IPNS ID that would provide both the front-end UI, but also serve any backend functions (mainly admin CMS type functions I have in mind)

Thanks for reading!

I don’t know much about p2phttp apart from that its primary function is handle serialization of HTTP reqs/responses onto libp2p streams.
I have not seen it presented as a solution to establish browser to server connectivity but I could be wrong.
Tagging @MarcoPolo / @marten

Is it just a matter of patience before js-libp2p gets its own js-p2phttp library?

This not in the plans at the moment and I’m not aware of discussion

What is relevant to this topic is a specification proposal for libp2p + HTTP. You can read the current version of the spec and follow the discussion here: https://github.com/libp2p/specs/pull/508

1 Like

I think you’re asking about when you’ll be able to make HTTP requests using a libp2p stream inside JS. If so, you’re correct. We are trying to get something like this out soon-ish. Feel free to follow https://github.com/libp2p/specs/pull/508 for updates.