Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
doc/plugin-api: major overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
skenqbx committed Apr 21, 2015
1 parent 2a65fae commit a432c05
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions doc/plugin-api.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,52 @@ module.exports = myPlugin;

## RAIL Plugin Events

### 'plugin-call'
These events are emitted on the `RAIL` object.

### Event: 'plugin-call'
Emitted when a new `Call` object is created.

`function(Call, ?Object=)`

### 'plugin-configure'
### Event: 'plugin-configure'
Emitted after a new request configuration has been pushed onto the stack.

`function(Call, Object)`

### 'plugin-request'
### Event: 'plugin-request'
Emitted directly after the request object has been created.

`function(Call, Object, Request)`

### 'plugin-response'
### Event: 'plugin-response'
Emitted when the response headers have been received.

`function(Call, Object, Response)`

## Interceptable Events
Specific events emitted on the `Call` object can be intercepted.
These _interceptable events_ are designed to gain complete control over the request workflow and allow implementing even non-trivial & asynchronous features as a plugin.

As an example for such a non-trivial feature see the [redirect plugin](../lib/plugins/redirect.js).

The methods beginning with two underscores `__` are defined as plugin interface.

### call.\_\_emit(event, var_args)
Invokes the next pending interceptor or emits the event.

On each call to `__emit()` only one interceptor is invoked, this way plugins can _blackhole_ responses by not calling `__emit()` after the response has been processed.

### call.\_\_intercept(event, interceptor)
Registers an interceptor `function(Call, Object, *)` for an event.

### call.\_\_clear()
Removes all registered interceptors.

### 'request'
### Event: 'request'
Emitted one tick after the request object has been created.

### 'response'
### Event: 'response'
Emitted after the response headers have been received.

### 'error'
### Event: 'error'
Emitted on an error in context of a request.

0 comments on commit a432c05

Please sign in to comment.