## 4.1.4.2.2.14  Extension API of the Application Router
A detailed list of the features and functions provided by the application router extension API.
The application router extension API enables you to create new instances of the application router, manage the approuter instance, and insert middleware using the Node.js 'connect' framework. This section contains detailed information about the following areas:
- Approuter Extension API Reference
- Middleware Slot
## Approuter Extension API Reference
The application router uses the 'Connect' framework for the insertion of middleware components. You can reuse all connect middleware within the application router directly.
Approuter Extension API Functions
| approuter()   | Creates a new instance of the application router                                                                                                                                                                                                                            |
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| first         | Defines a 'middleware slot' (a slot for the insertion of mid- dleware) immediately after the connect application is cre- ated, and before any application router middleware  Tip This is a good place to insert infrastructure logic, for example, logging and monitoring. |
| beforeRequestHandler     | Defines a 'middleware slot' before the standard application router request handling, that is; static resource serving or forwarding to destinations.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| beforeErrorHandler       | Defines a 'middleware slot' before the standard application router error handling                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| start(options, callback) | Starts the application router with the given options. • options this argument is optional. If provided, it should be an object which can have any of the following properties: • port - a TCP port the application router will listen to (string, optional) • workingDir - the working directory for the appli- cation router, should contain the xs-app.json file (string, optional) • extensions - an array of extensions, each one is an object as defined in Application Router Exten- sions (optional) • xsappConfig - An object representing the con- tent which is usually put in xs-app.json file. If this property is present it will take precedence over the content of xs-app.json . • callback - optional function with signature callback(err) . It is invoked when the application router has started or an error has occurred. If not provided and an error occurs (for example the port is busy), the application will abort. |
| close(callback)          | Stops the application router. • callback - optional function with signature callback(err) . It is invoked when the application router has stopped or an error has occurred.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
## Middleware Slot
Manage the insertion of middleware slots with the application router.
use(path, handler)
## Related Information
Middleware Connect Framework Extending the Application Router [page 513]