This class provides Ravel, a lightweight but powerful framework for the rapid creation of enterprise Node.js applications which scale horizontally with ease and support the latest in web technology.
Extends EventEmitter
const Ravel = require('ravel');
const app = new Ravel();
The base class of Ravel Error
s, which associate
http status codes with your custom errors.
const Ravel = require('ravel');
class NotFoundError extends Ravel.Error {
constructor (msg) {
super(msg, Ravel.httpCodes.NOT_FOUND);
}
}
The base class for Ravel DatabaseProvider
s. See
DatabaseProvider
for more information.
const DatabaseProvider = require('ravel').DatabaseProvider;
class MySQLProvider extends DatabaseProvider {
// ...
}
The base class for Ravel AuthenticationProvider
s. See
AuthenticationProvider
for more information.
const AuthenticationProvider = require('ravel').AuthenticationProvider;
class GoogleOAuth2Provider extends AuthenticationProvider {
// ...
}
A dictionary of useful http status codes. See HTTPCodes for more information.
const Ravel = require('ravel');
console.log(Ravel.httpCodes.NOT_FOUND);
The base class for Ravel Module
s. See
Module
for more information.
const Module = require('ravel').Module;
class MyModule extends Module {
// ...
}
module.exports = MyModule;
The base class for Ravel Routes
. See
Routes
for more information.
const Routes = require('ravel').Routes;
class MyRoutes extends Routes {
// ...
}
module.exports = MyRoutes;
Creates a new Ravel app instance.
const Ravel = require('ravel');
const app = new Ravel();
The current working directory of the app using the ravel library, so that client modules can be loaded with relative paths.
Return the app instance of Logger.
See Logger
for more information.
app.log.error('Something terrible happened!');
A hash of all built-in error types.
Value is true
iff init() or start() has been called on this app instance.
Value is true
iff listen() or start() has been called on this app instance.
The underlying HTTP server for this Ravel instance. Only available after listen() (i.e. use @postlisten).
Initializes the application, when the client is finished supplying parameters and registering modules, resources routes and rooms.
Starts the application. Must be called after initialize()
.
Intializes and starts the application.
Stops the application. A no op if the server isn't running.
Set a parameter.
(string)
The key for the parameter.
(Any)
The value for the parameter.
Object
:
The parameter value.
Get a parameter.
(string)
The key for the parameter.
Any
:
The parameter value, or undefined if it is not required and not set.
Register a Module
or a plain class with Ravel. Must be a flie exporting a single class.
This method is not generally meant to be used directly, unless you wish to give
your Module
a custom name. Instead, use app.modules
(see Ravel.modules
).
(string)
The path to the module.
(string)
The name for the module, which will be used for dependency injection.
app.module('./modules/mymodule', 'mymodule');
Recursively register Module
s and plain classes with Ravel (see Ravel.module
),
automatically naming them based on their relative path. All files within this directory (recursively)
should export a single class which may or may not extend Module
.
(string)
The directory to recursively scan for .js files.
These files should export a single class extending Ravel.Module.
// recursively load all Modules in a directory
app.modules('./modules');
// a Module 'modules/test.js' in ./modules can be injected as `@inject('test')`
// a Module 'modules/stuff/test.js' in ./modules can be injected as `@inject('stuff.test')`
Register a RESTful Resource
with Ravel.
This method is not generally meant to be used directly.
Instead, use app.resources
(see Ravel.resources
).
(string)
The path of the resource module to require(...).
app.resource('./resources/myresource');
Recursively register Resource
s with Ravel (see Ravel.resource
).
(string)
The directory to start scanning recursively for .js files.
// recursively load all Resources in a directory
app.resources('./resources');
Module
s are plain old node.js modules exporting a single class which encapsulates
application logic and middleware. Module
s support dependency injection of core
Ravel services and other Modules alongside npm dependencies (no relative require
's!).
Module
s are instantiated safely in dependency-order, and cyclical
dependencies are detected automatically.
const inject = require('ravel').inject;
const Module = require('ravel').Module;
@inject('path', 'fs', 'custom-module')
class MyModule extends Module {
constructor (path, fs, custom) {
super();
this.path = path;
this.fs = fs;
this.custom = custom;
}
aMethod () {
this.log.info('In aMethod!');
//...
}
}
module.exports = MyModule
const inject = require('ravel').inject;
const Module = require('ravel').Module;
@inject('path', 'fs', 'custom-module')
class MyModule {
constructor (path, fs, custom) {
this.path = path;
this.fs = fs;
this.custom = custom;
}
aMethod () {
// since we didn't extend Ravel.Module, we can't use this.log here.
}
}
module.exports = MyModule
const inject = require('ravel').inject;
const Module = require('ravel').Module;
class MyMiddleware extends Module {
async someMiddleware (ctx, next) {
//...
await next;
}
}
module.exports = MyModule
Methods decorated with @postinit
will fire after Ravel.init().
const Module = require('ravel').Module;
const postinit = Module.postinit;
class MyModule extends Module {
@postinit
doSomething () {
//...
}
}
Methods decorated with @prelisten
will fire at the beginning of Ravel.listen().
const Module = require('ravel').Module;
const prelisten = Module.prelisten;
class MyModule extends Module {
@prelisten
doSomething () {
//...
}
}
Methods decorated with @koaconfig
will fire after Ravel has set up koa
with all of its core global middleware (such as for error handling and
authentication/authorization) but before any Routes
or Resource
classes are loaded. Ravel is intentionally conservative with global
middleware to keep your routes as computationally efficient as possible.
It is highly recommended that Ravel apps follow the same heuristic,
declaring middleware in Routes
or Resource
classes at the class or
method level (as necessary). If, however, global middleware is desired,
@koaconfig
provides the appropriate hook for configuration.
const Module = require('ravel').Module;
const postlisten = Module.postlisten;
class MyModule extends Module {
@koaconfig
configureKoa (koaApp) { // a reference to the internal koa app object
//...
}
}
Methods decorated with @postlisten
will fire at the end of Ravel.listen().
const Module = require('ravel').Module;
const postlisten = Module.postlisten;
class MyModule extends Module {
@postlisten
doSomething () {
//...
}
}
Methods decorated with @preclose
will fire at the beginning of Ravel.close().
const Module = require('ravel').Module;
const preclose = Module.preclose;
class MyModule extends Module {
@preclose
doSomething () {
//...
}
}
The @authconfig
decorator for Module
classes. Tags the target
Module
as providing implementations of @authconfig
-related methods.
See authconfig
for more information.
const Module = require('ravel').Module;
const authconfig = Module.authconfig;
@authconfig
class MyAuthConfigModule extends Module {}
A reference to the ravel instance with which this Module is registered.
The injection name for this module.
Ravel's pre-packaged error types.
The logger for this Module
. Will log messages prefixed with the Module
name.
See Logger
for more information.
this.log.trace('A trace message');
this.log.verbose('A verbose message');
this.log.debug('A debug message');
this.log.info('A info message');
this.log.warn('A warn message');
this.log.error('A error message');
this.log.critical('A critical message');
// string interpolation is supported
this.log.info('Created record with id=%s', '42');
// Errors are supported
this.log.error('Something bad happened!', new Error('Ahh!'));
A reference to the internal Ravel key-value store connection (redis). See node-redis for more information.
An Object with a get() method, which allows easy access to ravel.get().
See Ravel.get
for more information.
this.params.get('some ravel parameter');
Most Ravel database connections are retrieved using the transaction-per-request
pattern (see transaction
).
If, however, your application needs to initiate a connection to a database which
is not triggered by an HTTP request (at startup, for example) then this method is
the intended approach. This method is meant to yield connections in much the same
way as @transaction
. See the examples below and
TransactionFactory
for more details.
const Module = require('ravel').Module;
const prelisten = Module.prelisten;
class MyModule extends Module {
// in this example, database initialization is
// performed at application start-time via
// the // @prelisten decorator
@prelisten
doInitDb () {
// open connections to specific, named database providers.
// like // @transaction, you can also supply no names (just
// the async function) to open connections to ALL registered
// DatabaseProviders
this.db.scoped('mysql', 'rethinkdb', async function (ctx) {
// can use ctx.transaction.mysql (an open connection)
// can use ctx.transaction.rethinkdb
});
}
}
Provides Ravel with a simple mechanism for registering koa
routes, which should generally only be used
for serving templated pages or static content (not for building RESTful APIs, for which Ravel.Resource
is more applicable). Clients extend this abstract superclass to create a Routes
module.
(any)
const inject = require('ravel').inject;
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
const before = Routes.before;
// you can inject your own Modules and npm dependencies into Routes
@inject('koa-bodyparser', 'fs', 'custom-module')
class MyRoutes extends Routes {
constructor (bodyParser, fs, custom) {
super('/'); // base path for all routes in this class
this.bodyParser = bodyParser(); // make bodyParser middleware available
this.fs = fs;
this.custom = custom;
}
// will map to /app
@mapping(Routes.GET, 'app')
@before('bodyParser') // use bodyParser middleware before handler
async appHandler (ctx) {
// ctx is a koa context object.
// await on Promises, and set ctx.body to create a body for response
// "OK" status code will be chosen automatically unless configured via ctx.status
// Extend and throw a Ravel.Error to send an error status code
}
}
module.exports = MyRoutes;
Used with the @mapping decorator to indicate the GET
HTTP verb.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.GET, '/something')
async handler (ctx) {
//...
}
}
Used with the @mapping decorator to indicate the POST
HTTP verb.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.POST, '/something')
async handler (ctx) {
//...
}
}
Used with the @mapping decorator to indicate the PUT
HTTP verb.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.PUT, '/something')
async handler (ctx) {
//...
}
}
Used with the @mapping decorator to indicate the DELETE
HTTP verb.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.DELETE, '/something')
async handler (ctx) {
//...
}
}
The @before
decorator for Routes
and Resource
classes.
See before
for more information.
The @transaction
decorator for Routes
and Resource
classes.
See transaction
for more information.
The @authenticated
decorator for Routes
and Resource
classes.
See authenticated
for more information.
Subclasses must call super(basePath)
.
(string)
The base path for all routes in this class. Should be unique within an application.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/user/:userId');
}
// will map to /user/:id/projects/:id
@mapping(Routes.GET, '/projects/:id')
async handler (ctx) {
// can access ctx.params.userId and ctx.params.id here
// ...
}
}
A reference to the ravel instance with which this Module is registered.
Ravel's pre-packaged error types.
The logger for this Routes
class. Will log messages prefixed with the Routes
class name.
See Logger
for more information.
this.log.trace('A trace message');
this.log.verbose('A verbose message');
this.log.debug('A debug message');
this.log.info('A info message');
this.log.warn('A warn message');
this.log.error('A error message');
this.log.critical('A critical message');
// string interpolation is supported
this.log.info('Created record with id=%s', '42');
// Errors are supported
this.log.error('Something bad happened!', new Error('Ahh!'));
A reference to the internal Ravel key-value store connection (redis). See node-redis for more information.
What might be referred to as a controller in other frameworks, a Resource
module defines
HTTP methods on an endpoint, supporting the session-per-request transaction pattern via Ravel
middleware. Resource
s also support dependency injection, allowing for the easy creation of
RESTful interfaces to your Module
-based application logic. Resources are really just a thin
wrapper around Routes
, using specially-named handler functions (get
, getAll
, post
,
put
, putAll
, delete
, deleteAll
) instead of @mapping
. This convention-over-configuration
approach makes it easier to write proper REST APIs with less code, and is recommended over
"carefully chosen" @mapping
s in a Routes
class.
Omitting any or all of the specially-named handler functions is fine, and will result in a
501 NOT IMPLEMENTED
status when that particular method/endpoint is requested.
Resource
s inherit all the properties, methods and decorators of Routes
. See Routes
for more information. Note that @mapping
does not apply to Resources
.
Extends Routes
(any)
const inject = require('ravel').inject;
const Resource = require('ravel').Resource;
const before = Routes.before;
// you can inject your own Modules and npm dependencies into Resources
@inject(koa-bodyparser', 'fs', 'custom-module')
class PersonResource extends Resource {
constructor (bodyParser, fs, custom) {
super('/person'); // base path for all routes in this class
this.bodyParser = bodyParser(); // make bodyParser middleware available
this.fs = fs;
this.custom = custom;
}
// will map to GET /person
@before('bodyParser') // use bodyParser middleware before handler
async getAll (ctx) {
// ctx is a koa context object.
// await on Promises, and set ctx.body to create a body for response
// "OK" status code will be chosen automatically unless configured via ctx.status
// Extend and throw a Ravel.Error to send an error status code
}
// will map to GET /person/:id
async get (ctx) {
// can use ctx.params.id in here automatically
}
// will map to POST /person
async post (ctx) {}
// will map to PUT /person
async putAll (ctx) {}
// will map to PUT /person/:id
async put (ctx) {}
// will map to DELETE /person
async deleteAll (ctx) {}
// will map to DELETE /person/:id
async delete (ctx) {}
}
module.exports = PersonResource;
The @mapping
decorator is not be available for Resource
classes.
Subclasses must call super(basePath)
.
(string)
The base path for all routes in this class. Should be unique within an application.
const Resource = require('ravel').Resource;
class PersonResource extends Resource {
constructor () {
super('/user');
}
// will map to /user/:id
async get (ctx) {
// can access ctx.params.userId and ctx.params.id here
// ...
}
}
Dependency injection decorator for Ravel Modules
,
Resources
and Routes
.
Based on Aurelia @inject decorator, but without the
es6 module format. Since eliminating relative require()s
has always been one of the core goals of the Ravel
framework, this decorator takes strings instead of
actual references to require()d modules. This string
is either the name of the module to require, or the
registered name of a client Ravel Module. Ravel Modules
override npm modules.
This decorator simply annotates the class with modules which
should be injected when Ravel initializes. See util/injector
for the actual DI implementation.
(...any)
// @inject works the same way on Modules, Resources and Routes
const inject = require('ravel').inject;
const Module = require('ravel').Module;
@inject('path', 'fs', 'custom-module')
class MyModule extends Module {
constructor (path, fs, custom) {
super();
this.path = path;
this.fs = fs;
this.custom = custom;
}
aMethod() {
// can access this.fs, this.path or this.custom
}
}
The @mapping
decorator for Routes
classes. Indicates that
the decorated method should be mapped as a route handler using koa
.
Can also be applied at the class-level to indicate routes which do nothing except return a particular status code.
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
// will map to /projects
@mapping(Routes.GET, 'projects')
async handler (ctx) {
// ctx is a koa context object
}
}
const Ravel = reuqire('ravel');
const Routes = Ravel.Routes;
const mapping = Routes.mapping;
// class-level version will create a route '/' which responds with 501 in this case
@mapping(Routes.DELETE, 'projects', Ravel.httpCodes.NOT_IMPLEMENTED)
class MyRoutes extends Routes {
constructor (bodyParser) {
super('/');
this.bodyParser = bodyParser();
}
}
The @before
decorator for Routes
and Resource
classes. Indicates that
certain middleware should be placed on the given route before the method
which is decorated.
Can also be applied at the class-level to place middleware before all
@mapping
handlers.
References any middleware AsyncFunction
s available on this
.
See before
for more information.
(...any)
// Note: decorator works the same way on Routes or Resource classes
const inject = require('ravel').inject;
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
const before = Routes.before;
@inject('koa-bodyparser')
class MyRoutes extends Routes {
constructor (bodyParser) {
super('/');
this.bodyParser = bodyParser();
}
@mapping(Routes.GET, '/projects/:id')
@before('bodyParser') // method-level version only applies to this route
async handler (ctx) {
// in here, bodyParser will already have run,
// and ctx.request.body will be populated
}
}
// Note: decorator works the same way on Routes or Resource classes
const inject = require('ravel').inject;
const Routes = require('ravel').Resource;
const before = Resource.before;
@inject('koa-bodyparser')
@before('bodyParser') // class-level version applies to all routes in class.
class MyResource extends Resource {
constructor (bodyParser) {
super('/');
this.bodyParser = bodyParser();
}
async get(ctx) {
// in here, bodyParser will already have run,
// and ctx.request.body will be populated
}
}
The @transaction
decorator for opening a transaction on a Routes
or
Resource
handler method. Facilitates transaction-per-request.
Can also be applied at the class-level to open connections for all handlers
in that Route
or Resource
class.
Connections are available within the handler as an object ctx.transaction
, which
contains connections as values and DatabaseProvider
names as keys. Connections
will be closed automatically when the endpoint responds (do not close them yourself),
and will automatically roll-back changes if a DatabaseProvider
supports it (generally
a SQL-only feature).
(...String)
A list of database provider names to open connections for.
// Note: decorator works the same way on Routes or Resource classes
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.GET, 'app')
@transaction // open all connections within this handler
async appHandler (ctx) {
// ctx.transaction is an object containing
// keys for DatabaseProviders and values
// for their open connections
}
@mapping(Routes.GET, 'something')
@transaction('mysql', 'rethinkdb') // open one or more specific connections within this handler
async somethingHandler (ctx) {
// can use ctx.transaction.mysql
// can use ctx.transaction.rethinkdb
}
}
// Note: decorator works the same way on Routes or Resource classes
const Resource = require('ravel').Resource;
@transaction('mysql') // all handlers will have ctx.transaction.mysql
class MyResource extends Resource {
constructor () {
super('/');
}
async post (ctx) {
// can use ctx.transaction.mysql
}
}
Database transaction support for ravel
applications provided in two ways:
(any)
For use when middlewareTransaction can't be used (in other words,
outside of Routes
and Resources
). This method is made available through
Module.db.scoped
. See Module.db.scoped
for examples.
(Array)
Arguments beginning with 0-N Strings representing providers to open connections on,
followed by an async function which Will be provided with a context which contains
this.transaction.
Promise
:
A Promise which is resolved when inGen is finished running, or rejected if
an error was thrown.
Defines an abstract DatabaseProvider - a mechanism by which connections can be obtained and transactions can be entered and exited for a particular database provider such as MySQL (see ravel-mysql-provider for an example implementation).
(any)
(any)
Anything that should happen when this DatabaseProvider
is connected to a Ravel
application via require('provider-name')(app)
should happen here.
This includes, but is not limited to, the declaration of parameters supporting
this module via ravelInstance.registerParameter()
. If you override this constructor,
be sure to call super(ravelInstance, name)
.
string
:
The unique name of this DatabaseProvider.
Try to pick something unique within the Ravel ecosystem.
Anything that should happen just before a Ravel application starts listening
(app.listen()
) should happen here. If you override this hook, be sure to call super()
.
This function should return nothing. It is a good place to start connection
pools.
(Ravel)
An instance of a Ravel application.
End a transaction and close the connection. Rollback the transaction iff finalErr !== null.
(Object)
A connection object which was used throughout the transaction.
(boolean)
If true, commit, otherwise rollback.
Promise
:
Resolved, or rejected if there was an error while closing the connection.
The @authenticated
decorator for adding authentication middleware before an endpoint
within a Routes
or Resource
class.
Ensures that a user is signed in before flow proceeds to the endpoint handler. Can also be used without arguments.
Assumes that you've require
'd an AuthenticationProvider
, and that you
have set up an @authconfig
Module
.
If an object is passed as an argument to the decorator, it is used for configuration purposes, and supports the following keys:
See authconfig
and
AuthenticationProvider
for more information.
((Class | Method | Object))
A configuration object (returning a decorator), or the Method
or Class to directly apply this decorator to.
// Note: decorator works the same way on Routes or Resource classes
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
const authenticated = Routes.authenticated;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@authenticated({redirect: true}) // works at the method-level, with or without arguments
@mapping(Routes.GET, 'app')
async handler (ctx) {
// will redirect to this.params.get('login route') if not signed in
}
}
// Note: decorator works the same way on Routes or Resource classes
const Resource = require('ravel').Resource;
const authenticated = Resource.authenticated;
@authenticated // works at the class-level as well (with or without arguments)
class MyResource extends Resource {
constructor () {
super('/');
}
async handler (ctx) {
// will respond with a 401 if not signed in
}
}
A decorator for a module, indicating that it will offer specific functions which encapsulate the configuration of passport.js. For more information on how to create an @authconfig module, please see the README for a Ravel AuthenticationProvider.
(Class)
The class to declare as the
@authconfig
class.
The abstract superclass of AuthenticationProviders - modules which are capable of initializing Passport.js with a particular strategy, and seamlessly verifying requests issued by mobile clients via header tokens instead of sessions.
(any)
Anything that should happen when this AuthenticationProvider
is connected to a Ravel
application via require('provider-name')(app)
should happen here.
This includes, but is not limited to, the declaration of parameters supporting
this module via ravelInstance.registerParameter()
. If you override this constructor,
be sure to call super(ravelInstance)
.
(Ravel)
An instance of a Ravel application.
The name of the AuthenticationProvider. Override, and try to pick something unique within the Ravel ecosystem.
Initialize passport.js with a strategy.
An abstraction for a logging service which behaves like intel.
(any)
Log at the 'trace' level.
Log at the 'verbose' level.
Log at the 'debug' level.
Log at the 'info' level.
Log at the 'warn' level.
Log at the 'error' level.
Log at the 'critical' level.
Built-in error types are automatically translated into standard HTTP response status codes when thrown.
Base error type for Ravel, to be extended into semantic errors
which can be used within Ravel modules, as well as by clients'
APIs. These Error types are intended to encapsulate standard
things that can go wrong and, when used by a client, are
translated into HTTP status codes automatically in
Resource
responses
Extends Error
(any)
(any)
Access Error - Thrown when a user attempts to utilize functionality they are not authenticated to access
Extends RavelError
(any)
Authentication Error - Most useful for creating authentication providers
Extends RavelError
(any)
Duplicate Entry Error - Thrown when an attempt is made to insert a record into the database which violates a uniqueness constraint
Extends RavelError
(any)
Illegal Value Error - Thrown when the user supplies an illegal value
Extends RavelError
(any)
Not Allowed Error - Used to mark API functionality which is not permitted to be accessed under the current application configuration
Extends RavelError
(any)
Not Found Error - Thrown when something is expected to exist, but is not found.
Extends RavelError
(any)
Not Implemented Error - Used to mark API functionality which has not yet been implemented
Extends RavelError
(any)
Range Out Of Bounds Error - Used when a range of data is requested from a set which is outside of the bounds of that set.
Extends RavelError
(any)
Hash of HTTP Response Codes
HTTP MULTIPLE CHOICES.
number
:
The HTTP status code 300.
HTTP MOVED PERMANENTLY.
number
:
The HTTP status code 301.
HTTP TEMPORARY REDIRECT.
number
:
The HTTP status code 307.
HTTP PERMANENT REDIRECT.
number
:
The HTTP status code 308.
HTTP PAYMENT REQUIRED.
number
:
The HTTP status code 402.
HTTP METHOD NOT ALLOWED.
number
:
The HTTP status code 405.
HTTP PROXY AUTHENTICATION REQUESTED.
number
:
The HTTP status code 407.
HTTP PRECONDITION FAILED.
number
:
The HTTP status code 412.
HTTP REQUEST ENTITY TOO LARGE.
number
:
The HTTP status code 413.
HTTP REQUEST URI TOO LONG.
number
:
The HTTP status code 414.
HTTP UNSUPPORTED MEDIA TYPE.
number
:
The HTTP status code 415.
HTTP REQUESTED RANGE NOT SATISFIABLE.
number
:
The HTTP status code 416.
HTTP EXPECTATION FAILED.
number
:
The HTTP status code 417.
HTTP AUTHENTICATION TIMEOUT.
number
:
The HTTP status code 419.
HTTP UNPROCESSABLE ENTITY.
number
:
The HTTP status code 422.
HTTP FAILEDDEPENDENCY.
number
:
The HTTP status code 424.
HTTP UPGRADE REQUIRED.
number
:
The HTTP status code 426.
HTTP PRECONDITION REQUIRED.
number
:
The HTTP status code 428.
HTTP TOO MANY REQUESTS.
number
:
The HTTP status code 429.
HTTP REQUEST HEADER FIELDS TOO LARGE.
number
:
The HTTP status code 431.
HTTP BLOCKED BY WINDOWS PARENTAL CONTROLS.
number
:
The HTTP status code 450.
HTTP UNAVAILABLE FOR LEGAL REASONS.
number
:
The HTTP status code 451.
HTTP REQUEST HEADER TOO LARGE.
number
:
The HTTP status code 494.
HTTP TOKEN EXPIRED INVALID.
number
:
The HTTP status code 498.
HTTP CLIENT CLOSED REQUEST.
number
:
The HTTP status code 499.
HTTP INTERNAL SERVER ERROR.
number
:
The HTTP status code 500.
HTTP SERVICE UNAVAILABLE.
number
:
The HTTP status code 503.
HTTP HTTP VERSION NOT SUPPORTED.
number
:
The HTTP status code 505.
HTTP VARIANT ALSO NEGOTIATES.
number
:
The HTTP status code 506.
HTTP INSUFFICIENT STORAGE.
number
:
The HTTP status code 507.
HTTP BANDWIDTH LIMIT EXCEEDED.
number
:
The HTTP status code 509.
HTTP NETWORK NETWORK AUTHENTICATION REQUIRED.
number
:
The HTTP status code 511.
HTTP WEB SERVER IS DOWN.
number
:
The HTTP status code 521.
HTTP CONNECTION TIMED OUT.
number
:
The HTTP status code 522.
HTTP PROXY DECLINED REQUEST.
number
:
The HTTP status code 523.
HTTP A TIMEOUT OCCURRED.
number
:
The HTTP status code 524.
The @cache
decorator for Routes
and Resource
classes. Indicates that
response caching middleware should be placed on the given route before the method
which is decorated.
Can also be applied at the class-level to place caching middleware before all
@mapping
handlers.
References any middleware AsyncFunction
s available on this
.
See cache
for more information.
(...Any)
Options for the caching middleware, or undefined.
// Note: decorator works the same way on Routes or Resource classes
const Routes = require('ravel').Routes;
const mapping = Routes.mapping;
const cache = Routes.cache;
class MyRoutes extends Routes {
constructor () {
super('/');
}
@mapping(Routes.GET, '/projects/:id')
@cache // method-level version only applies to this route
async handler (ctx) {
// The response will automatically be cached when this handler is run
// for the first time, and then will be served instead of running the
// handler for as long as the cached response is available.
}
}
// Note: decorator works the same way on Routes or Resource classes
const Resource = require('ravel').Resource;
const cache = Resource.cache;
// class-level version applies to all routes in class, overriding any
// method-level instances of the decorator.
@cache({expire:60, maxLength: 100}) // expire is measured in seconds. maxLength in bytes.
class MyResource extends Resource {
constructor (bodyParser) {
super('/');
this.bodyParser = bodyParser();
}
async get(ctx) {
// The response will automatically be cached when this handler is run
// for the first time, and then will be served instead of running the
// handler for as long as the cached response is available (60 seconds).
}
}