0.0.9 • Published 12 years ago
restinpeace v0.0.9
REST in peace
A REST Client with Service Testing Framework
Stability: 1 - Experimental
api
rip.request(options, opt_callback)
Creates a new request object. Request
extends Stream
.
opt_callback
is an optional function(err, statusCode, headers, body)
.
options
contains the request parameters, with the following defaults:
{
proto: 'http',
host: 'localhost',
port: 80,
method: 'GET',
path: '/',
query: null, // object or string
body: null, // string or buffer
encoding: 'utf8', // only determines the request content-encoding
buffer: false // when set to true, response data is returned as Buffer
// with the complete listener.
}
examples
Using a callback & buffering response data
rip.request({host: 'www.google.com', buffer: true},
function(err, statusCode, headers, body) {
console.log(err ? err.message : err, statusCode, headers, body);
});
Using event listeners
rip.request({host: 'www.google.com'})
.on('complete', function(statusCode, headers, body) {
console.log('complete:', statusCode, headers, body);
})
.on('error', function(err) {
console.log('error:', err.message);
})
.pipe(fs.createWriteStream('./response.txt'));
Event: 'error'
function(err)
Emitted when a stream or connection error occurs. This event is directly followed by the end
event.
Event: 'headers'
function(statusCode, headers)
Event: 'data'
function(chunk)
Event: 'end'
function()
Event: 'complete'
function(statusCode, headers, body)
Only emitted when the request is completed without errors.
body
will always be null
if the buffer
option is not set.
request.abort()
request.write(chunk, opt_encoding)
request.end(opt_chunk, opt_encoding)
request.pipe(stream, opt_options)
license
(The MIT License)
Copyright (c) 2012 Malte-Thorben Bruns <skenqbx@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.