Giter VIP home page Giter VIP logo

bare-http1's Introduction

bare-http1

HTTP/1 library for JavaScript.

npm i bare-http1

http.Server supports most HTTP features, e.g. keep-alive, chunked encoding, and streaming responses.

Basic http.ClientRequest is implemented, temporarily it does NOT support keep-alive and protocol negotiation.

Usage

const http = require('bare-http1')

// Same API as Node.js

const server = http.createServer(function (req, res) {
  res.statusCode = 200
  res.setHeader('Content-Length', 10)
  res.write('hello world!')
  res.end()
})

server.listen(0, function () {
  const { port } = server.address()
  console.log('server is bound on', port)

  const client = http.request({ port }, res => {
    res.on('data', (data) => console.log(data.toString()))
  })
  client.end()
})

License

Apache-2.0

bare-http1's People

Contributors

kasperisager avatar mafintosh avatar yassernasc avatar hdegroote avatar lukks avatar butera-simone avatar

Stargazers

22388o⚡️  avatar  avatar  avatar Andrew Chou avatar  avatar

Watchers

Jonathan Brumley avatar  avatar jordi domenech avatar Andrew Osheroff avatar David Mark Clements avatar Eduard Castellano avatar Rahul Garg avatar Eugene Glova avatar Bagrat Bagoyan avatar Jan Keith Darunday avatar  avatar rafapaezbas avatar Miika avatar  avatar

Forkers

22388o

bare-http1's Issues

Request on('data',data) do not read stream

I have a method POST, but I can't figure out why it doesn't read the stream (body request), but for the 'end' totally works

  let body = '
  req.on('data',data => {
      body += data.toString();
    });
  req.on('end', () => {
      console.log('Received data:', body);
      res.statusCode = 200;
      res.setHeader('Content-Type', 'application/json');
      res.end(JSON.stringify({ message: 'Peer connected' }));
    });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.