Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
6878339
docs: update middleware documentation
buger Mar 3, 2026
d0075bb
feat(docs): update middleware documentation
buger Mar 3, 2026
588ea91
docs: restore content and enhance plugin guide
buger Mar 3, 2026
50c2465
Merge main into feat/update-middleware-docs-99
buger Mar 5, 2026
38b8bb4
Merge main into feat/update-middleware-docs-99
buger Mar 5, 2026
18a72ff
Apply suggestions from code review
sedkis Mar 5, 2026
95a4d73
feat(docs): address review comments on middleware docs PR
buger Mar 5, 2026
a4318c1
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
ec11f2f
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
0cc1249
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
478edd0
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
f61561c
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
a5e8f7e
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
d31a7bc
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
44a99bb
Merge main into feat/update-middleware-docs-99
buger Mar 6, 2026
a428e68
Merge main into feat/update-middleware-docs-99
buger Mar 7, 2026
1fb8976
Merge main into feat/update-middleware-docs-99
buger Mar 10, 2026
9bcf8d7
Merge main into feat/update-middleware-docs-99
buger Mar 10, 2026
a0b4ef8
Merge main into feat/update-middleware-docs-99
buger Mar 10, 2026
b75a554
Merge main into feat/update-middleware-docs-99
buger Mar 11, 2026
83868ca
Merge main into feat/update-middleware-docs-99
buger Mar 11, 2026
1004c61
Merge main into feat/update-middleware-docs-99
buger Mar 11, 2026
804ec24
Merge main into feat/update-middleware-docs-99
buger Mar 11, 2026
1dfb7e5
Merge main into feat/update-middleware-docs-99
buger Mar 12, 2026
1bb3208
Merge main into feat/update-middleware-docs-99
buger Mar 12, 2026
8979113
Merge main into feat/update-middleware-docs-99
buger Mar 12, 2026
51ad56c
Merge main into feat/update-middleware-docs-99
buger Mar 12, 2026
ed57b5b
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
778ab3e
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
cd004d7
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
ab65893
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
6124e8e
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
180ca12
Merge main into feat/update-middleware-docs-99
buger Mar 13, 2026
d633d24
Merge main into feat/update-middleware-docs-99
buger Mar 16, 2026
c593bf8
Merge main into feat/update-middleware-docs-99
buger Mar 17, 2026
89893f5
Merge main into feat/update-middleware-docs-99
buger Mar 17, 2026
815e0da
Merge main into feat/update-middleware-docs-99
buger Mar 17, 2026
9d8bc54
Merge main into feat/update-middleware-docs-99
buger Mar 17, 2026
72d4cd1
Merge main into feat/update-middleware-docs-99
buger Mar 17, 2026
48341db
Merge main into feat/update-middleware-docs-99
buger Mar 18, 2026
2db4316
Merge main into feat/update-middleware-docs-99
buger Mar 26, 2026
c3b3a16
Merge main into feat/update-middleware-docs-99
buger Mar 30, 2026
002a9d9
Merge main into feat/update-middleware-docs-99
buger Mar 30, 2026
e22f130
Merge main into feat/update-middleware-docs-99
buger Mar 30, 2026
2af2b7c
Merge main into feat/update-middleware-docs-99
buger Mar 30, 2026
13dd295
Merge main into feat/update-middleware-docs-99
buger Apr 1, 2026
429b7bd
Merge main into feat/update-middleware-docs-99
buger Apr 1, 2026
81cda3d
Merge main into feat/update-middleware-docs-99
buger Apr 1, 2026
ebfa401
Merge main into feat/update-middleware-docs-99
buger Apr 7, 2026
edcd4bd
Merge main into feat/update-middleware-docs-99
buger Apr 9, 2026
50c17e6
Merge main into feat/update-middleware-docs-99
buger Apr 10, 2026
e044923
Merge main into feat/update-middleware-docs-99
buger Apr 10, 2026
4c7ee10
Merge main into feat/update-middleware-docs-99
buger Apr 10, 2026
16e53ef
Merge main into feat/update-middleware-docs-99
buger Apr 11, 2026
08d02ed
Merge main into feat/update-middleware-docs-99
buger Apr 11, 2026
36cc49a
Merge main into feat/update-middleware-docs-99
buger Apr 16, 2026
0dadf31
Merge main into feat/update-middleware-docs-99
buger Apr 16, 2026
2b83a20
Merge main into feat/update-middleware-docs-99
buger Apr 21, 2026
1249083
Merge main into feat/update-middleware-docs-99
buger Apr 22, 2026
e05645b
Merge main into feat/update-middleware-docs-99
buger Apr 22, 2026
0d51a1e
Merge main into feat/update-middleware-docs-99
buger Apr 22, 2026
f13a533
Merge main into feat/update-middleware-docs-99
buger Apr 22, 2026
fb62def
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 22, 2026
3a6dd56
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 22, 2026
68ff0e9
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 22, 2026
174a243
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 23, 2026
cd60ef2
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 23, 2026
c88a77d
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 23, 2026
23e3792
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 24, 2026
5c30399
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 24, 2026
81b6eec
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 29, 2026
e15f84c
Merge main into feat/update-middleware-docs-99
probelabs[bot] Apr 29, 2026
e2f3533
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
25c2492
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
896b42a
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
3b358d5
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
141b8bb
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
48890a2
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
321e607
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
74ef431
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 6, 2026
b099f7f
Merge main into feat/update-middleware-docs-99
probelabs[bot] May 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions api-management/plugins/plugin-developer-guide.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
title: Plugin Developer Guide
description: A comprehensive guide for developers building custom plugins for the Tyk Gateway.
---

import { Callout } from '/components/callout';

This guide provides an in-depth technical reference for developers building custom plugins for the Tyk Gateway. It is intended for developers who want to extend the functionality of the Tyk Gateway with custom logic.

This guide covers the following topics:

* An overview of the Tyk Gateway's middleware architecture.
* A detailed reference of all built-in middleware.
* Information on the data available to custom plugins.
* Best practices for plugin development.

For information on how to write plugins in a specific language, see the following guides:

* [Go Plugins](/api-management/plugins/golang)
* [Python Plugins](/api-management/plugins/python)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [Python Plugins](/api-management/plugins/python)

* [gRPC Plugins](/api-management/plugins/grpc)

## Data Available to Plugins

Custom plugins have access to a rich set of data, including the request and response objects, the session object, and metadata.
Comment thread
sedkis marked this conversation as resolved.
Outdated

### Request and Response Objects

The request and response objects provide access to the HTTP request and response, including headers, body, and other information.

### Session Object

The session object contains information about the authenticated user, including their API key, rate limits, and access rights. The session object is only available in the `PostKeyAuth`, `Post`, and `Response` stages.

### Metadata

The metadata object is a key-value store that can be used to pass data between middleware and plugins. The metadata object is available in all stages of the middleware execution chain.

## Best Practices for Plugin Development

* **Keep plugins small and focused.** Each plugin should have a single responsibility.
* **Handle errors gracefully.** Plugins should not crash the Tyk Gateway.
* **Write unit tests for your plugins.** This will help to ensure that your plugins are working correctly.
* **Use the metadata object to pass data between plugins.** This is more efficient than modifying the request or response objects directly.

## Middleware Execution Order

The Tyk Gateway processes requests in a series of stages, with middleware executing in a specific order. Understanding this execution order is crucial for developing custom plugins that interact with the request and response lifecycle.

The middleware execution chain is divided into five stages:

1. **Pre (Pre-authentication)**: Executes before any authentication checks. This stage is ideal for tasks like header injection, request validation, or IP filtering.
2. **AuthCheck (Authentication)**: Responsible for authenticating the client. Custom authentication plugins can be injected here.
3. **PostKeyAuth (Post-authentication)**: Executes after a successful authentication. This stage can be used for tasks like granular access control or rate limiting.
4. **Post (Final Request Processing)**: Performs final transformations and checks before proxying the request to the upstream service.
5. **Response**: Executes on the response from the upstream service before it is returned to the client.

The following diagram illustrates the middleware execution chain and the points where custom plugins can be injected.

![Tyk Middleware Execution Chain](/assets/images/middleware-chain.png)

## Built-in Middleware Reference

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing between this page and the other page.
Maybe we need a dedicated built-in middleware page?


The following table provides an exhaustive list of all built-in middleware in the Tyk Gateway, along with their execution stage and data access capabilities.

| Middleware | Execution Stage | Session Access | Context Vars Access | Metadata Access | Configurable |
| :--- | :--- | :--- | :--- | :--- | :--- |
| VersionCheck | Pre | No | Yes | No | Yes |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add custom plugin hooks in this so we can see where the execute relatively speaking

| CORSMiddleware | Pre | No | Yes | No | Yes |
| RateCheckMW | Pre | Yes | Yes | No | Yes |
| IPWhiteListMiddleware | Pre | No | No | No | Yes |
| IPBlackListMiddleware | Pre | No | No | No | Yes |
| CertificateCheckMW | Pre | No | No | No | Yes |
| OrganizationMonitor | Pre | No | No | No | Yes |
| Oauth2KeyExists | AuthCheck | Yes | Yes | Yes | Yes |
| ExternalOAuthMiddleware | AuthCheck | Yes | Yes | Yes | Yes |
| BasicAuthKeyIsValid | AuthCheck | Yes | Yes | Yes | Yes |
| HTTPSignatureValidationMiddleware | AuthCheck | Yes | Yes | Yes | Yes |
| JWTMiddleware | AuthCheck | Yes | Yes | Yes | Yes |
| OpenIDMW | AuthCheck | Yes | Yes | Yes | Yes |
| StripAuth | AuthCheck | No | No | No | Yes |
| KeyExpired | PostKeyAuth | Yes | No | No | Yes |
| AccessRightsCheck | PostKeyAuth | Yes | No | No | Yes |
| GranularAccessMiddleware | PostKeyAuth | Yes | No | No | Yes |
| RateLimitAndQuotaCheck | PostKeyAuth | Yes | No | No | Yes |
| RateLimitForAPI | Post | No | No | No | Yes |
| GraphQLMiddleware | Post | No | Yes | Yes | Yes |
| ValidateJSON | Post | No | Yes | No | Yes |
| RequestSigning | Post | No | Yes | No | Yes |
| ValidateRequest | Post | No | Yes | No | Yes |
| TransformMiddleware | Post | No | Yes | Yes | Yes |
| URLRewriteMiddleware | Post | No | Yes | No | Yes |
| mockResponseMiddleware | Post | No | Yes | No | Yes |
| ResponseMiddleware | Response | Yes | Yes | Yes | Yes |

## Custom Plugin Injection Points (Hooks)

Custom plugins can be injected into the middleware chain at specific points, known as hooks. These hooks allow you to execute custom logic at different stages of the request and response lifecycle.

The following hooks are available for custom plugins:

* **Pre-request Hook**: Executes at the beginning of the `Pre` stage.
* **Authentication Hook**: Executes during the `AuthCheck` stage.
* **Post-authentication Hook**: Executes at the beginning of the `PostKeyAuth` stage.
* **Post-request Hook**: Executes at the beginning of the `Post` stage.
* **Response Hook**: Executes at the beginning of the `Response` stage.

Each hook provides access to the request and response objects, as well as the session and metadata. The data available at each hook is detailed in the middleware reference table above.
66 changes: 55 additions & 11 deletions api-management/traffic-transformation.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
---
title: "Transform Traffic by using Tyk Middleware"
description: "Learn how to transform API traffic using Tyk's middleware capabilities."
keywords: "Overview, Allow List, Block List, Ignore Authentication, Internal Endpoint, Request Method , Request Body , Request Headers , Response Body, Response Headers, Request Validation, Mock Response, Virtual Endpoints, Go Templates, JQ Transforms, Request Context Variables"
title: "Traffic Transformation"
description: "An overview of how to transform API traffic using Tyk's middleware capabilities."
keywords: "Overview, Middleware, Plugins, Traffic Transformation"
sidebarTitle: "Overview"
---

## Overview

When you configure an API on Tyk, the Gateway will proxy all requests received at the listen path that you have defined through to the upstream (target) URL configured in the API definition. Responses from the upstream are likewise proxied on to the originating client. Requests and responses are processed through a powerful [chain of middleware](/api-management/traffic-transformation#request-middleware-chain) that perform security and processing functions.
When you configure an API on Tyk, the Gateway processes all requests through a powerful chain of middleware. This middleware performs security checks, transformations, and other processing on the request before it reaches your upstream service, and on the response before it is returned to the client.

Within that chain are a highly configurable set of optional middleware that can, on a per-endpint basis:
- apply processing to [API requests](#middleware-applied-to-the-api-request) before they are proxied to the upstream service
- apply customization to the [API response](#middleware-applied-to-the-api-response) prior to it being proxied back to the client

Tyk also supports a powerful custom plugin feature that enables you to add custom processing at different stages in the processing chains. For more details on custom plugins please see the [dedicated guide](/api-management/plugins/overview#).
This page provides a high-level overview of the middleware execution chain and the most commonly used middleware for transforming traffic. For a detailed technical reference of all middleware and custom plugin development, see the [Plugin Developer Guide](/api-management/plugins/plugin-developer-guide).

### Middleware applied to the API Request

Expand Down Expand Up @@ -102,6 +98,54 @@ The [Response Body Transform](/api-management/traffic-transformation/response-bo
#### Response Header Transform

The [Response Header Transform](/api-management/traffic-transformation/response-headers) middleware allows you to modify the header information provided in the response before it leaves the Gateway and is passed to the client.
### Request Middleware Chain

<img src="/img/diagrams/middleware-execution-order@3x.png" alt="Middleware execution flow" />
## Middleware Execution Chain

The Tyk Gateway processes requests in five distinct stages. The following diagram illustrates the middleware execution chain and shows where custom plugins can be injected.

![Tyk Middleware Execution Chain](/assets/images/middleware-chain.png)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this image exist?


## Commonly Used Middleware

The following is a curated list of the most commonly used, user-configurable middleware, organized by execution stage.

### Pre (Pre-authentication)

* **CORS**: Manages Cross-Origin Resource Sharing for your APIs.
* **IP Whitelisting/Blacklisting**: Restricts access to your APIs based on IP address.
* **Request Size Limiting**: Enforces size limits on incoming requests.

### AuthCheck (Authentication)

* **OAuth 2.0**: Secures your APIs using the OAuth 2.0 protocol.
* **JWT**: Validates JSON Web Tokens.
* **Basic Authentication**: Uses standard basic authentication.

### PostKeyAuth (Post-authentication)

* **Rate Limiting and Quotas**: Enforces rate limits and quotas on a per-key basis.
* **Access Rights**: Controls access to specific endpoints based on the API key.

### Post (Final Request Processing)

* **Header Transformations**: Modifies request and response headers.
* **URL Rewriting**: Rewrites the request URL before it is proxied to the upstream service.
* **Mock Responses**: Returns a mock response without proxying the request to the upstream service.

### Response

* **Response Transformations**: Modifies the response body before it is returned to the client.

## Custom Plugins

Tyk allows you to inject custom logic into the middleware chain using custom plugins. This is a powerful feature that enables you to implement custom authentication, transformations, and other logic.

Custom plugins can be injected at the following points in the middleware chain:

* **Pre-request**: Before any other processing.
* **Authentication**: To implement custom authentication.
* **Post-authentication**: After a successful authentication.
* **Post-request**: Before the request is proxied to the upstream service.
* **Response**: On the response from the upstream service.

For more information on developing custom plugins, see the [Plugin Developer Guide](/api-management/plugins/plugin-developer-guide).
Loading