rail API
- Exports
- Class: RAIL
- Class: Call
- Class: ReplayBuffer
An object holding all built-in plugins.
Copies all properties, headers in this case, from either the source
or the defaults
to the target
.
Copies all properties in keys
from either the source
or the defaults
to the target
.
Parses an URL into an object with proto
, host
, port
& path
.
Applies proto
, host
, port
& path
of an URL to the target
.
A global RAIL
object pre-loaded with buffer
, json
, redirect
, cookies
, timeout
, validate
& retry
plugin.
A convenience method ala. https.request()
using RAIL.globalClient
.
See rail.call().
RAIL
extends events.EventEmitter
.
Creates a new RAIL
object.
opt_options
{string} proto
- One ofhttps
,http2
orhttp
, defaults tohttps
{Object} request
- holding default request options, seehttps.request()
{Object} *
- plugin options{number} maxReplayBuffer
The maximum size of a buffered request body, see Class: ReplayBuffer
An object holding loaded plugins.
The default protocol for all calls.
The default request options for all calls.
Loads a plugin.
{string} name
The name of the plugin{?function=} opt_plugin
A plugin constructor{?Object=} opt_options
Optional plugin options
Returns the newly loaded plugin on success, null
when the plugin is already loaded and false
when no constructor could be located.
rail.use('buffer'/*, opt_options */); // load built-in plugin
rail.use('my', MyPlugin/*, opt_options */); // load a custom plugin
Factory method to create new Call
objects, think https.request()
.
opt_options
When opt_options
is a string, it is handled like opt_options.url
.
{string} proto
Seenew RAIL(opt_options)
{string} url
When given, the request options are set accordingly{Object} request
The request options, see io.js or node.js{Object|boolean} *
Any plugin options, configured plugins are auto-loaded{number} maxReplayBuffer
The maximum size of a buffered request body, see Class: ReplayBuffer
Notes
- request options
hostname
,auth
,localAddress
&socketPath
are not supported - request options can also be provided directly besides proto & plugin options
Call
extends stream.Writable
.
Creates a new Call
object. Not supposed to be used directly, see rail.call().
A boolean indicating the state of the call.
A boolean indicating the state of the writable stream.
The currently active request
stream, if any.
The currently active response
stream, if any.
Immediately abort any request, free the ReplayBuffer
and prevent any further requests.
Internally request.abort()
is called.
Note: An error
is very likely to be emitted after a call to abort()
.
See writable.write().
See writable.end().
Returns this
.
Emitted after the request object has been created and the ReplayBuffer
has been flushed.
function({Object} request)
Emitted when a pending connect or active request is aborted.
Emitted after the response headers have been received.
function({Object} response)
function({string} plugin, {string} status, {?string} opt_message)
The ReplayBuffer
is used to buffer the request body in case of redirects, retries or other use-cases. ReplayBuffer
is an EE.
The plugin API offers call.__buffer() to enable this buffer.
Creates a new ReplayBuffer
object.
{number} opt_max
is the maximum size of all buffered chunks, defaults to134217728
(128 MiB)
The maximum number of bytes allowed to buffer.
The current number of bytes buffered.
A boolean controlling if the buffer is active or in streaming mode.
A boolean indicating if the buffer accepts more data.
A boolean indicating that the buffer size is exceeding the maximum allowed size.
Copy buffered chunks to writable
using replayBuffer.replay()
and relay all future chunks to writable
.
Push a new chunk to the buffer.
Throws an error when the buffer has already ended
.
Returns false
when the buffer size exceeds max
, otherwise true
.
Copy all buffered chunks to writable
.
Empties the buffer and sets replayBuffer.buffer
to false
.
Prevents further addition of chunks and clear the writable stream.
Emitted when the buffer is ended. This is the last moment a can modify the request configuration.