This guide covers the basics for creating Blocks. Blocks are functions that run before or after an API endpoint is executed. They can be used to modify the API request, to modify the API response or to execute common tasks like audit logging, caching, rate limiting or recording analytics. Multiple Blocks can be executed before or after an API request. Blocks are optional.
To programmatically create a Block, see the API Builder.Block API reference.
Place all Block files in the project's
- Loads the
- Calls the module's
Block.extend()method, passing in an object defining the block identifier and logic to execute
- Exports the defined block using the
Set the following keys in the object passed to the
method to define the Block:
|true||Block name. This name should be used when specifying blocks in your API endpoint definition. Assign the name value to either the |
|true||Human useful description to display in the documentation.|
|true||The function containing the logic for your block. All of your runnable code goes in the |
|false||Determines whether to generate API documentation (true) or not (false). The default value is |
The following Block replaces the
id parameter to
2 and logs the change.