Skip to main content
Before continuing, make sure you’re familiar with:You’ll also want to make sure you’ve already built something to apply middleware to.
Middleware enables additional control of your logic at pivotal points of execution. They are separate pieces of logic that can run before the logic executes (before input validation) or after the logic executes (after the response is generated, but before it is delivered). Middleware can be applied to:
  • APIs
  • Custom Functions
  • Background Tasks
  • AI Tools
Middleware is available on any paid plan. There are two types of middleware:
  • Pre-middleware that runs before input validation
  • Post-middleware that runs after the logic executes and a response is generated, but before it is delivered
You’ll need to understand response and exception types when building your middleware. Response types are used to determine how the middleware handles generating a response once it’s done executing.
Response TypeDescription
mergeMerges the response of the middleware with the existing response. If the middleware response contains a key that already exists in the generated response, it will be overwritten.
replaceReplaces the existing response entirely with the new response
Exception methods are used to determine how the middleware handles errors that occur during execution.
Exception MethodDescription
criticalStops execution completely and returns an error
silentSilently ignores errors
rethrowWhen paired with post-middleware, it allows the post-middleware to run even when an error occurs in the pre-middleware. Good for error logging or monitoring.
Middleware has predefined inputs that can not be changed. These inputs are:
  • vars - The variables from the parent object. This could be either the inputs sent to the workflow for a pre-middleware, or the response generated by the parent object for a post-middleware.
  • type - The type of middleware (pre or post).

Building Middleware in Xano

1

Open the Middleware library

From the left-hand menu, click Library and then Middleware.
2

Click Add Middleware

Click the Add Middleware button in the top-right corner.
  • Visually
  • XanoScript
1

Provide some basic information

Give your middleware a name, description, and any tags you’d like to apply. Choose your response type and exception method.
middleware-20251014-113051

Providing basic information for Middleware

2

Build the middleware logic

Once you’ve build your middleware, you’ll need to apply it to the workflows you want it to run with.

Applying Middleware to Workflows

Middleware can be applied at the workspace level, workflow group level (like API groups), or onto individual workflows. If no customizations are set on a workflow, it will inherit middleware settings from their parent object, such as the group they reside in or the workspace. You can quickly disable middleware by clicking the toggle and remove it completely from the object by clicking the .

Workspace level

From your Dashboard, click⚙️ and choose Middleware from the menu.
middleware-20251014-114300

Accessing the Middleware menu on your workspace


middleware-20251014-113949

Select the workflow type you want to apply the middleware to.


middleware-20251014-114037

Select the appropriate option to apply either pre or post middleware.

Applying middleware to a workflow group

Group level middleware only applies to APIs.
From an API group, click and select Middleware.
middleware-20251014-114329

Accessing the Middleware menu on an API group


middleware-20251014-114401

Check the Customize box next to the type of middleware you want to apply to that API group. You'll see the Add buttons appear once you do.

Applying middleware to an individual workflow

From the workflow, click and select Middleware.
middleware-20251014-114536

Accessing the Middleware menu on a workflow


middleware-20251014-114037

Check the Customize box next to the type of middleware you want to apply to that workflow. You'll see the Add buttons appear once you do.

I