The http module from node.js, but for React Native.
When you require('http')
in
react-native,
this module will be loaded.
adapted from John Hiesey's stream-http, thanks John!
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__'
})
})
var http = require('http');
where opts
are:
opts.method='GET'
- http method verbopts.path
- path string, example:'/foo/bar?baz=555'
opts.headers={}
- as an object mapping key names to string or Array valuesopts.host=window.location.host
- http hostopts.port=window.location.port
- http portopts.responseType
- response type to set on the underlying xhr object
The callback will be called with the response object.
A shortcut for
options.method = 'GET';
var req = http.request(options, cb);
req.end();
Set an http header.
Get an http header.
Remove an http header.
Write some data to the request body.
If only 1 piece of data is written, data
can be a FormData, Blob, or
ArrayBuffer instance. Otherwise, data
should be a string or a buffer.
Close and send the request body, optionally with additional data
to append.
Return an http header, if set. key
is case-insensitive.
- res.statusCode, the numeric http response code
- res.headers, an object with all lowercase keys
With npm do:
npm install react-native-http
MIT