1.0.1 • Published 6 months ago

@libp2p/http-server v1.0.1

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
6 months ago

@libp2p/http-ping

@libp2p/http-server

libp2p.io Discuss codecov CI

HTTP server components

About

This module exports several utility functions to make creating HTTP servers that run over HTTP quick and easy.

Example - Create a Node.js server

import { createLibp2p } from 'libp2p'
import { http } from '@libp2p/http'
import { nodeServer } from '@libp2p/http-server'
import { createServer } from 'node:http'

const server = createServer((req, res) => {
  res.write('Hello world!')
  res.end()
})

const node = await createLibp2p({
  // ...other settings
  services: {
    http: http({
      server: nodeServer(server)
    })
  }
})

Example - Create a Node.js server in a browser

The previous example can also run in a non-Node.js environment by using the supplied createServer function which implements the same API as Node.js just without depending on any Node.js internals.

import { createServer } from '@libp2p/http-server/node'

const server = createServer((req, res) => {
  res.write('Hello world!')
  res.end()
})

Install

$ npm i @libp2p/http-server

Browser <script> tag

Loading this module through a script tag will make its exports available as Libp2pHttpServer in the global namespace.

<script src="https://unpkg.com/@libp2p/http-server/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.