Giter Site home page Giter Site logo

http-browserify's Introduction

http-browserify

The http module from node.js, but for browsers.

When you require('http') in browserify, this module will be loaded.

example

var http = require('http');

http.get({ path : '/beep' }, function (res) {
    var div = document.getElementById('result');
    div.innerHTML += 'GET /beep<br>';
    
    res.on('data', function (buf) {
        div.innerHTML += buf;
    });
    
    res.on('end', function () {
        div.innerHTML += '<br>__END__';
    });
});

http methods

var http = require('http');

var req = http.request(options, cb)

options can have:

  • method
  • path
  • headers={}, as an object mapping key names to string or Array values
  • host=window.location.host
  • port=window.location.port

The callback will be called with the response object.

var req = http.get(options, cb)

A shortcut for

options.method = 'GET';
var req = http.request(options, cb);
req.end();

request methods

req.setHeader(key, value)

Set an http header.

req.write(data)

Write some data to the request body.

req.end(data)

Close and send the request body, optionally with additional data to append.

response methods

res.getHeader(key)

Return an http header, if set. key is case-insensitive.

response attributes

  • res.statusCode, the numeric http response code
  • res.headers, an object with all lowercase keys

response events

  • data
  • end
  • error

compatibility

This module has been tested and works with:

  • Internet Explorer 5.5, 6, 7, 8, 9
  • Firefox 3.5
  • Chrome 7.0
  • Opera 10.6
  • Safari 5.0

Multipart streaming responses are buffered in all versions of Internet Explorer and are somewhat buffered in Opera. In all the other browsers you get a nice unbuffered stream of "data" events when you send down a content-type of multipart/octet-stream or similar.

protip

You can do:

var bundle = browserify({
    require : { http : 'http-browserify' }
});

in order to map "http-browserify" over require('http') in your browserified source.

http-browserify's People

Contributors

aredridel avatar brycebaril avatar coverslide avatar erithmetic avatar forbeslindesay avatar kumavis avatar max-mapper avatar relvao avatar tehshrike avatar tellnes avatar terinjokes avatar

Watchers

 avatar

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.