Optional
options: RestfulApiOptionsInitPrivate
Readonly
_apiThe api that the context belongs to
Context
Private
_optionsReadonly
childrenThe children of the context
Context
Context.current.children; // The children of the current context
Optional
Readonly
Private
conditionThe condition for the context to be executed
Context
Optional
Readonly
Private
parentThe parent context
Context
The api that the context belongs to
Get the context's error handler
Get a map of all the data of the context
A map with all the data of the context
Context.current.map; // A map with all the data of the context
Static
currentDefine the action function for this context Only one action function is allowed in a context. It does mark the request as handled and will not call any other anything after it.
The action function
The context itself
Search for paths starting with the given path. Is the same as Condition.describe
the path that the condition should check for
the action happening when the condition is met
Context.current.any("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Search for paths matching the given regex. Is the same as Condition.describe
the regex that the condition should check for
the action happening when the condition is met
Context.current.any("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Search for paths starting with the given path. Is the same as Condition.describe This is a shorthand for Context.any and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.any("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.any("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Search for paths matching the given regex. Is the same as Condition.describe This is a shorthand for Context.any and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.any(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.any(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Get the context stack for the given request
The request to get the context stack for
The response to get the context stack for
The context stack
Context
Context.current.contextStack(req, res); // The context stack for the given request
Get all the data of the context
A map with all the data of the context
Context.current.data(); // A map with all the data of the context
Get the data with the given key
The key of the data to get
The data with the given key
Context.current.data("key"); // The data with the given key
Match requests with the method DELETE.
the action happening when the condition is met
Context.current.delete(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method DELETE.
the path that the condition should check for
the action happening when the condition is met
Context.current.delete("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method DELETE.
the regex that the condition should check for
the action happening when the condition is met
Context.current.delete(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method DELETE. This is a shorthand for Context.delete and then Context.action inside.
the action happening when the condition is met
Context.current.delete(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.delete(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method DELETE. This is a shorthand for Context.delete and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.delete("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.delete("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method DELETE. This is a shorthand for Context.delete and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.delete(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.delete(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Search for paths starting with the given path. Is the same as Condition.any
the path that the condition should check for
the action happening when the condition is met
Context.current.describe("/hello", function() {
// ctx is available here via [this] keyword
// Do something
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Search for paths matching the given regex. Is the same as Condition.any
the regex that the condition should check for
the action happening when the condition is met
Context.current.describe("/hello", function() {
// ctx is available here via [this] keyword
// Do something
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Search for paths starting with the given path. Is the same as Condition.any This is a shorthand for Context.describe and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.describe("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.describe("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Search for paths matching the given regex. Is the same as Condition.any This is a shorthand for Context.describe and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.describe(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.describe(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Execute the context
The request to execute the context for
The response to execute the context for
Whether the context was successfully executed or not
Context
Context.current.execute(req, res); // Whether the context was executed or not
Match requests with the method GET.
the action happening when the condition is met
Context.current.get(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method GET.
the path that the condition should check for
the action happening when the condition is met
Context.current.get("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method GET.
the regex that the condition should check for
the action happening when the condition is met
Context.current.get(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method GET. This is a shorthand for Context.get and then Context.action inside.
the action happening when the condition is met
Context.current.get(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.get(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method GET. This is a shorthand for Context.get and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.get("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.get("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method GET. This is a shorthand for Context.get and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.get(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.get(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Get the request path to access this context (including the parent path, if any. Use Context.getRoutingPath to get the path without the parent path)
The request path to access this context
Get the request path to access this context (without the parent path, if any. Use Context.getPath to get the path with the parent path)
The request path to access this context
Set the context's error handler
Match requests with the method HEAD.
the action happening when the condition is met
Context.current.head(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method HEAD.
the path that the condition should check for
the action happening when the condition is met
Context.current.head("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method HEAD.
the regex that the condition should check for
the action happening when the condition is met
Context.current.head(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method HEAD. This is a shorthand for Context.head and then Context.action inside.
the action happening when the condition is met
Context.current.head(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.head(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method HEAD. This is a shorthand for Context.head and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.head("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
res.status(200).json({ message: "Hello World!" }).end();
});
});
// Is the same as this:
Context.current.head("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method HEAD. This is a shorthand for Context.head and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.head(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.head(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Get information about the context and its children
Information about the context and its children
Context.current.info(); // Information about the context and its children
Initialize the context with a handler
The handler to initialize the context with
The context itself
Context
Context.current.init(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method OPTIONS.
the action happening when the condition is met
Context.current.options(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method OPTIONS.
the path that the condition should check for
the action happening when the condition is met
Context.current.options("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method OPTIONS.
the regex that the condition should check for
the action happening when the condition is met
Context.current.options(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method OPTIONS. This is a shorthand for Context.options and then Context.action inside.
the action happening when the condition is met
Context.current.options(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.options(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method OPTIONS. This is a shorthand for Context.options and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.options("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method OPTIONS. This is a shorthand for Context.options and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.options(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests with the method PATCH.
the action happening when the condition is met
Context.current.patch(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method PATCH.
the path that the condition should check for
the action happening when the condition is met
Context.current.patch("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method PATCH.
the regex that the condition should check for
the action happening when the condition is met
Context.current.patch(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method PATCH. This is a shorthand for Context.patch and then Context.action inside.
the action happening when the condition is met
Context.current.patch(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.patch(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method PATCH. This is a shorthand for Context.patch and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.patch("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.patch("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method PATCH. This is a shorthand for Context.patch and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.patch(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.patch(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests with the method POST.
the action happening when the condition is met
Context.current.post(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method POST.
the path that the condition should check for
the action happening when the condition is met
Context.current.post("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method POST.
the regex that the condition should check for
the action happening when the condition is met
Context.current.post(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method POST. This is a shorthand for Context.post and then Context.action inside.
the action happening when the condition is met
Context.current.post(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.post(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method POST. This is a shorthand for Context.post and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.post("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.post("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method POST. This is a shorthand for Context.post and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.post(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.post(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests with the method PUT.
the action happening when the condition is met
Context.current.put(function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests starting with the given path and requests with the method PUT.
the path that the condition should check for
the action happening when the condition is met
Context.current.put("/hello", function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests matching the given regex and requests with the method PUT.
the regex that the condition should check for
the action happening when the condition is met
Context.current.put(//hello/, function() {
// ctx is available here via [this] keyword
// Do something
});
Match requests with the method PUT. This is a shorthand for Context.put and then Context.action inside.
the action happening when the condition is met
Context.current.put(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.put(function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests starting with the given path and requests with the method PUT. This is a shorthand for Context.put and then Context.action inside.
the path that the condition should check for
the action happening when the condition is met
Context.current.put("/hello", async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.put("/hello", function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Match requests matching the given regex and requests with the method PUT. This is a shorthand for Context.put and then Context.action inside.
the regex that the condition should check for
the action happening when the condition is met
Context.current.put(//hello/, async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
// Is the same as this:
Context.current.put(//hello/, function() {
this.action(async (req, res) => {
res.status(200).json({ message: "Hello World!" }).end();
});
});
Set the data with the given key to the given value
The key of the data to set
The value to set the data to
The context itself
Context.current.setData("key", "value"); // The context itself
Return the json representation of the context
The json representation of the context
Define the use function for this context. Use functions are called when the context is executed. They can be used to add middleware to the context.
The use function
The context itself
Context.current.use(function(req, res, next) {
// ctx is available here via [this] keyword
// Do something
});
Create a new context and add it to the children of the current context with a condition and a handler
The condition for the context to be executed
The handler to initialize the context with
The context itself
Context.current.when(new ContextConditionPath("/hello"), function() {
// ctx is available here via [this] keyword
// Do something
});
Generated using TypeDoc
The Context class is used to describe a route. Context can be nested using ContextChildCondition as children (generated using the when function). TODO: More documentation