Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/libp2p/go-libp2p-http
HTTP on top of libp2p
https://github.com/libp2p/go-libp2p-http
go http ipfs libp2p
Last synced: 6 days ago
JSON representation
HTTP on top of libp2p
- Host: GitHub
- URL: https://github.com/libp2p/go-libp2p-http
- Owner: libp2p
- License: mit
- Created: 2017-02-03T23:22:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-10T08:17:16.000Z (4 months ago)
- Last Synced: 2025-02-08T14:04:12.402Z (13 days ago)
- Topics: go, http, ipfs, libp2p
- Language: Go
- Homepage:
- Size: 292 KB
- Stars: 64
- Watchers: 22
- Forks: 20
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-libp2p-http
[](https://travis-ci.org/libp2p/go-libp2p-http)
[](https://codecov.io/gh/libp2p/go-libp2p-http)
[](https://github.com/RichardLitt/standard-readme)> HTTP on top of libp2p
Package `p2phttp` allows to serve HTTP endpoints and make HTTP requests through [libp2p](https://github.com/libp2p/libp2p) using Go's standard "http" and "net" stack.
Instead of the regular "host:port" addressing, `p2phttp` uses a Peer ID and lets libp2p take care of the routing, thus taking advantage of features like multi-routes, NAT transversal and stream multiplexing over a single connection.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)## Install
This package is a library that uses Go modules for dependency management.
## Usage
Full documentation can be read at [Godoc](https://godoc.org/github.com/libp2p/go-libp2p-http). The important bits follow.
A simple `http.Server` on libp2p works as:
```go
listener, _ := gostream.Listen(host1, p2phttp.DefaultP2PProtocol)
defer listener.Close()
go func() {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hi!"))
})
server := &http.Server{}
server.Serve(listener)
}()
```The listener is provided by https://github.com/libp2p/go-libp2p-gostream .
A client just needs to be initialized with a custom libp2p host-based transport to perform requests to such server:
```go
tr := &http.Transport{}
tr.RegisterProtocol("libp2p", p2phttp.NewTransport(clientHost))
client := &http.Client{Transport: tr}
res, err := client.Get("libp2p://Qmaoi4isbcTbFfohQyn28EiYM5CDWQx9QRCjDh3CTeiY7P/hello")
```## Contribute
PRs accepted.
## License
MIT © Protocol Labs, Inc.